@@ -5,8 +5,6 @@ const convertEiselLemire = @import("convert_eisel_lemire.zig").convertEiselLemir
const convertSlow = @import("convert_slow.zig").convertSlow;
const convertHex = @import("convert_hex.zig").convertHex;
const optimize = true;
pub const ParseFloatError = error{
InvalidCharacter,
};
@@ -41,25 +39,23 @@ pub fn parseFloat(comptime T: type, s: []const u8) ParseFloatError!T {
return convertHex(T, n);
}
if (optimize) {
if (convertFast(T, n)) |f| {
return f;
}
if (convertFast(T, n)) |f| {
return f;
}
if (T == f16 or T == f32 or T == f64) {
// If significant digits were truncated, then we can have rounding error
// only if `mantissa + 1` produces a different result. We also avoid
// redundantly using the Eisel-Lemire algorithm if it was unable to
// correctly round on the first pass.
if (convertEiselLemire(T, n.exponent, n.mantissa)) |bf| {
if (!n.many_digits) {
if (T == f16 or T == f32 or T == f64) {
// If significant digits were truncated, then we can have rounding error
// only if `mantissa + 1` produces a different result. We also avoid
// redundantly using the Eisel-Lemire algorithm if it was unable to
// correctly round on the first pass.
if (convertEiselLemire(T, n.exponent, n.mantissa)) |bf| {
if (!n.many_digits) {
return bf.toFloat(T, n.negative);
}
if (convertEiselLemire(T, n.exponent, n.mantissa + 1)) |bf2| {
if (bf.eql(bf2)) {
return bf.toFloat(T, n.negative);
}
if (convertEiselLemire(T, n.exponent, n.mantissa + 1)) |bf2| {
if (bf.eql(bf2)) {
return bf.toFloat(T, n.negative);
}
}
}
}
}