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/ › fmt/ › parse_float/ › convert_fast.zig › convertFast
convertFast
convert_fast.convertFast
pub fn convertFast (comptime T : type , n : Number (T )) ?T
File
Code
pub fn convertFast (comptime T : type , n : Number (T )) ?T {
const MantissaT = common .mantissaType (T );
if (!isFastPath (T , n )) {
return null ;
}
const info = FloatInfo .from (T );
var value : T = 0 ;
if (n .exponent <= info .max_exponent_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 {
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 ;
}