pub fn from(comptime T: type) Self {
return switch (T) {
f16 => .{
// Fast-Path
.min_exponent_fast_path = -4,
.max_exponent_fast_path = 4,
.max_exponent_fast_path_disguised = 7,
.max_mantissa_fast_path = 2 << std.math.floatMantissaBits(T),
// Slow + Eisel-Lemire
.mantissa_explicit_bits = std.math.floatFractionalBits(T),
.infinite_power = 0x1f,
// Eisel-Lemire
.smallest_power_of_ten = -26, // TODO: refine, fails one test
.largest_power_of_ten = 4,
.minimum_exponent = -15,
// w >= (2m+1) * 5^-q and w < 2^64
// => 2m+1 > 2^11
// => 2^11*5^-q < 2^64
// => 5^-q < 2^53
// => q >= -23
.min_exponent_round_to_even = -22,
.max_exponent_round_to_even = 5,
},
f32 => .{
// Fast-Path
.min_exponent_fast_path = -10,
.max_exponent_fast_path = 10,
.max_exponent_fast_path_disguised = 17,
.max_mantissa_fast_path = 2 << std.math.floatMantissaBits(T),
// Slow + Eisel-Lemire
.mantissa_explicit_bits = std.math.floatFractionalBits(T),
.infinite_power = 0xff,
// Eisel-Lemire
.smallest_power_of_ten = -65,
.largest_power_of_ten = 38,
.minimum_exponent = -127,
.min_exponent_round_to_even = -17,
.max_exponent_round_to_even = 10,
},
f64 => .{
// Fast-Path
.min_exponent_fast_path = -22,
.max_exponent_fast_path = 22,
.max_exponent_fast_path_disguised = 37,
.max_mantissa_fast_path = 2 << std.math.floatMantissaBits(T),
// Slow + Eisel-Lemire
.mantissa_explicit_bits = std.math.floatMantissaBits(T),
.infinite_power = 0x7ff,
// Eisel-Lemire
.smallest_power_of_ten = -342,
.largest_power_of_ten = 308,
.minimum_exponent = -1023,
.min_exponent_round_to_even = -4,
.max_exponent_round_to_even = 23,
},
f80 => .{
// Fast-Path
.min_exponent_fast_path = -27,
.max_exponent_fast_path = 27,
.max_exponent_fast_path_disguised = 46,
.max_mantissa_fast_path = 2 << std.math.floatMantissaBits(T),
// Slow + Eisel-Lemire
.mantissa_explicit_bits = std.math.floatFractionalBits(T),
.infinite_power = 0x7fff,
// Eisel-Lemire.
// NOTE: Not yet tested (no f80 eisel-lemire implementation)
.smallest_power_of_ten = -4966,
.largest_power_of_ten = 4932,
.minimum_exponent = -16382,
// 2^65 * 5^-q < 2^80
// 5^-q < 2^15
// => q >= -6
.min_exponent_round_to_even = -6,
.max_exponent_round_to_even = 28,
},
f128 => .{
// Fast-Path
.min_exponent_fast_path = -48,
.max_exponent_fast_path = 48,
.max_exponent_fast_path_disguised = 82,
.max_mantissa_fast_path = 2 << std.math.floatMantissaBits(T),
// Slow + Eisel-Lemire
.mantissa_explicit_bits = std.math.floatFractionalBits(T),
.infinite_power = 0x7fff,
// Eisel-Lemire.
// NOTE: Not yet tested (no f128 eisel-lemire implementation)
.smallest_power_of_ten = -4966,
.largest_power_of_ten = 4932,
.minimum_exponent = -16382,
// 2^113 * 5^-q < 2^128
// 5^-q < 2^15
// => q >= -6
.min_exponent_round_to_even = -6,
.max_exponent_round_to_even = 49,
},
else => unreachable,
};
}