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 › atanBinary16
atanBinary16
atan.atanBinary16
fn atanBinary16 (x : f16 ) f16
File
Code
fn atanBinary16 (x : f16 ) f16 {
const atanhi : []const f32 = &.{
4.6364760399e-01 ,
7.8539812565e-01 ,
9.8279368877e-01 ,
1.5707962513e+00 ,
};
const aT : []const f32 = &.{
0x1.fffcccp-1 ,
-0x1.52e8ccp-2 ,
0x1.522336p-3 ,
};
const hx : u16 = @bitCast (x );
const ix = hx & 0x7fff ;
const sign = (hx >> 15 ) != 0 ;
if (ix >= 0x6800 ) {
if (math .isNan (x )) {
return x ;
}
const z = atanhi [3 ] + 0x1p-120 ;
return @floatCast (if (sign ) -z else z );
}
const x_ : f32 , const id : ?usize = blk : {
if (ix < 0x3700 ) {
if (ix < 0x2400 ) {
if (ix < 0x400 ) {
mem .doNotOptimizeAway (x * x );
}
return x ;
}
break :blk .{ @floatCast (x ), null };
} else {
const x_ : f32 = @floatCast (@abs (x ));
if (ix < 0x3cc0 ) {
if (ix < 0x3980 ) {
break :blk .{ (2.0 * x_ - 1.0 ) / (2.0 + x_ ), 0 };
}
else {
break :blk .{ (x_ - 1.0 ) / (x_ + 1.0 ), 1 };
}
} else {
if (ix < 0x40e0 ) {
break :blk .{ (x_ - 1.5 ) / (1.0 + 1.5 * x_ ), 2 };
}
else {
break :blk .{ -1.0 / x_ , 3 };
}
}
}
};
const z = x_ * x_ ;
const s = aT [0 ] + z * (aT [1 ] + z * aT [2 ]);
if (id ) |id_ | {
const z_ = atanhi [id_ ] + x_ * s ;
return @floatCast (if (sign ) -z_ else z_ );
} else {
return @floatCast (x_ * s );
}
}