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.
pubinlinefncmpf2(comptimeT: type, comptimeRT: type, a: T, b: T) RT {
constbits = @typeInfo(T).float.bits;
constsrep_t = @Int(.signed, bits);
constrep_t = @Int(.unsigned, bits);
constsignificandBits = std.math.floatMantissaBits(T);
constexponentBits = std.math.floatExponentBits(T);
constsignBit = (@as(rep_t, 1) << (significandBits + exponentBits));
constabsMask = signBit - 1;
constinfT = comptimestd.math.inf(T);
constinfRep = @as(rep_t, @bitCast(infT));
constaInt = @as(srep_t, @bitCast(a));
constbInt = @as(srep_t, @bitCast(b));
constaAbs = @as(rep_t, @bitCast(aInt)) & absMask;
constbAbs = @as(rep_t, @bitCast(bInt)) & absMask;
// If either a or b is NaN, they are unordered.if (aAbs > infReporbAbs > infRep) returnRT.Unordered;
// If a and b are both zeros, they are equal.if ((aAbs | bAbs) == 0) return .Equal;
// If at least one of a and b is positive, we get the same result comparing
// a and b as signed integers as we would with a floating-point compare.
if ((aInt & bInt) >= 0) {
if (aInt < bInt) {
return .Less;
} elseif (aInt == bInt) {
return .Equal;
} elsereturn .Greater;
} else {
// Otherwise, both are negative, so we need to flip the sense of the
// comparison to get the correct result. (This assumes a twos- or ones-
// complement integer representation; if integers are represented in a
// sign-magnitude representation, then this flip is incorrect).
if (aInt > bInt) {
return .Less;
} elseif (aInt == bInt) {
return .Equal;
} elsereturn .Greater;
}
}