Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › math/ › atan.zig › atanBinary32
atanBinary32
atan.atanBinary32
fn atanBinary32 (x : f32 ) f32
File
Code
fn atanBinary32 (x : f32 ) f32 {
const atanhi : []const f32 = &.{
4.6364760399e-01 ,
7.8539812565e-01 ,
9.8279368877e-01 ,
1.5707962513e+00 ,
};
const atanlo : []const f32 = &.{
5.0121582440e-09 ,
3.7748947079e-08 ,
3.4473217170e-08 ,
7.5497894159e-08 ,
};
const aT : []const f32 = &.{
3.3333328366e-01 ,
-1.9999158382e-01 ,
1.4253635705e-01 ,
-1.0648017377e-01 ,
6.1687607318e-02 ,
};
const hx : u32 = @bitCast (x );
const ix = hx & 0x7fff_ffff ;
const sign = (hx >> 31 ) != 0 ;
if (ix >= 0x4c80_0000 ) {
if (math .isNan (x )) {
return x ;
}
const z = atanhi [3 ] + 0x1p-120 ;
return if (sign ) -z else z ;
}
const x_ , const id : ?usize = blk : {
if (ix < 0x3ee00000 ) {
if (ix < 0x39800000 ) {
if (ix < 0x00800000 ) {
mem .doNotOptimizeAway (x * x );
}
return x ;
}
break :blk .{ x , null };
} else {
const x_ = @abs (x );
if (ix < 0x3f98_0000 ) {
if (ix < 0x3f30_0000 ) {
break :blk .{ (2.0 * x_ - 1.0 ) / (2.0 + x_ ), 0 };
}
else {
break :blk .{ (x_ - 1.0 ) / (x_ + 1.0 ), 1 };
}
} else {
if (ix < 0x401c_0000 ) {
break :blk .{ (x_ - 1.5 ) / (1.0 + 1.5 * x_ ), 2 };
}
else {
break :blk .{ -1.0 / x_ , 3 };
}
}
}
};
const z = x_ * x_ ;
const w = z * z ;
const s1 = z * (aT [0 ] + w * (aT [2 ] + w * aT [4 ]));
const s2 = w * (aT [1 ] + w * aT [3 ]);
if (id ) |id_ | {
const z_ = atanhi [id_ ] - ((x_ * (s1 + s2 ) - atanlo [id_ ]) - x_ );
return if (sign ) -z_ else z_ ;
} else {
return x_ - x_ * (s1 + s2 );
}
}