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.
frexpGeneric
math.frexpGeneric
fnfrexpGeneric(comptimeT: type, x: T, e: *c_int) T
fnfrexpGeneric(comptimeT: type, x: T, e: *c_int) T {
// libc expects `*e` to be unspecified in this case; an unspecified C value
// should be a valid value of the relevant type, yet Zig's std
// implementation sets it to `undefined` -- which can even be nonsense
// according to the type (int). Therefore, we're setting it to a valid
// int value in Zig -- a zero.
//
// This mirrors the handling of infinities, where libc also expects
// unspecified for the value of `*e` and Zig std sets it to a zero.
if (math.isNan(x)) {
e.* = 0;
returnx;
}
constr = math.frexp(x);
e.* = r.exponent;
returnr.significand;
}