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 standard library.
std › fmt › parse_float › convert_fast › convertFast Public Function convertFast Doc Source Public Function std.fmt.parse_float.convert_fast.convertFast
pub fn convertFast (comptime T : type , n : Number (T )) ?T Params File fmt/parse_float/convert_fast.zig: 105
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 pub fn convertFast (comptime T : type , n : Number (T )) ?T {
const MantissaT = common .mantissaType (T );
if (!isFastPath (T , n )) {
return null ;
}
// TODO: x86 (no SSE/SSE2) requires x87 FPU to be setup correctly with fldcw
const info = FloatInfo .from (T );
var value : T = 0 ;
if (n .exponent <= info .max_exponent_fast_path ) {
// normal fast path
value = @as (T , @floatFromInt (n .mantissa ));
value = if (n .exponent < 0 )
value / fastPow10 (T , @as (usize , @intCast (-n .exponent )))
else
value * fastPow10 (T , @as (usize , @intCast (n .exponent )));
} else {
// disguised fast path
const shift = n .exponent - info .max_exponent_fast_path ;
const mantissa = math .mul (MantissaT , n .mantissa , fastIntPow10 (MantissaT , @as (usize , @intCast (shift )))) catch return null ;
if (mantissa > info .max_mantissa_fast_path ) {
return null ;
}
value = @as (T , @floatFromInt (mantissa )) * fastPow10 (T , info .max_exponent_fast_path );
}
if (n .negative ) {
value = -value ;
}
return value ;
}