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 › compiler_rt/ › rem_pio2f.zig
rem_pio2f.zig
Index
File
Code
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
// https://git.musl-libc.org/cgit/musl/tree/src/math/__rem_pio2f.c
const std = @import ("std" );
const rem_pio2_large = @import ("rem_pio2_large.zig" ).rem_pio2_large ;
const math = std .math ;
const toint = 1.5 / math .floatEps (f64 );
const pio4 = 0x1.921fb6p-1 ;
const invpio2 = 6.36619772367581382433e-01 ;
// pio2_1: first 25 bits of pi/2
const pio2_1 = 1.57079631090164184570e+00 ;
// pio2_1t: pi/2 - pio2_1
const pio2_1t = 1.58932547735281966916e-08 ;
// Returns the remainder of x rem pi/2 in *y
// use double precision for everything except passing x
// use rem_pio2_large() for large x
pub fn rem_pio2f (x : f32 , y : *f64 ) i32 {
var tx : [1 ]f64 = undefined ;
var ty : [1 ]f64 = undefined ;
var @"fn" : f64 = undefined ;
var ix : u32 = undefined ;
var n : i32 = undefined ;
var sign : bool = undefined ;
var e0 : u32 = undefined ;
var ui : u32 = undefined ;
ui = @bitCast (x );
ix = ui & 0x7fffffff ;
if (ix < 0x4dc90fdb ) {
// Use a specialized rint() to get fn.
@"fn" = @as (f64 , @floatCast (x )) * invpio2 + toint - toint ;
n = @intFromFloat (@"fn" );
y .* = x - @"fn" * pio2_1 - @"fn" * pio2_1t ;
if (y .* < -pio4 ) {
n -= 1 ;
@"fn" -= 1 ;
y .* = x - @"fn" * pio2_1 - @"fn" * pio2_1t ;
} else if (y .* > pio4 ) {
n += 1 ;
@"fn" += 1 ;
y .* = x - @"fn" * pio2_1 - @"fn" * pio2_1t ;
}
return n ;
}
if (ix >= 0x7f800000 ) {
y .* = x - x ;
return 0 ;
}
sign = ui >> 31 != 0 ;
e0 = (ix >> 23 ) - (0x7f + 23 );
ui = ix - (e0 << 23 );
tx [0 ] = @as (f32 , @bitCast (ui ));
n = rem_pio2_large (&tx , &ty , @as (i32 , @intCast (e0 )), 1 , 0 );
if (sign ) {
y .* = -ty [0 ];
return -n ;
}
y .* = ty [0 ];
return n ;
}