diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 359451628733..d23259235ace 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -9,7 +9,7 @@ const assert = std.debug.assert; const mem = std.mem; const unicode = std.unicode; const meta = std.meta; -const errol = @import("fmt/errol.zig"); +const ryu128 = @import("fmt/ryu128.zig"); const lossyCast = std.math.lossyCast; const expectFmt = std.testing.expectFmt; @@ -763,27 +763,27 @@ fn formatFloatValue( options: FormatOptions, writer: anytype, ) !void { - // this buffer should be enough to display all decimal places of a decimal f64 number. - var buf: [512]u8 = undefined; - var buf_stream = std.io.fixedBufferStream(&buf); + var buf: [ryu128.bufferSize(.decimal, f64)]u8 = undefined; if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { - formatFloatScientific(value, options, buf_stream.writer()) catch |err| switch (err) { - error.NoSpaceLeft => unreachable, + const s = ryu128.format(&buf, value, .{ .mode = .scientific, .precision = options.precision }) catch |err| switch (err) { + error.BufferTooSmall => "(float)", }; + return formatBuf(s, options, writer); } else if (comptime std.mem.eql(u8, fmt, "d")) { - formatFloatDecimal(value, options, buf_stream.writer()) catch |err| switch (err) { - error.NoSpaceLeft => unreachable, + const s = ryu128.format(&buf, value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) { + error.BufferTooSmall => "(float)", }; + return formatBuf(s, options, writer); } else if (comptime std.mem.eql(u8, fmt, "x")) { + var buf_stream = std.io.fixedBufferStream(&buf); formatFloatHexadecimal(value, options, buf_stream.writer()) catch |err| switch (err) { error.NoSpaceLeft => unreachable, }; + return formatBuf(buf_stream.getWritten(), options, writer); } else { invalidFmtError(fmt, value); } - - return formatBuf(buf_stream.getWritten(), options, writer); } pub const Case = enum { lower, upper }; @@ -886,8 +886,7 @@ fn formatSizeImpl(comptime base: comptime_int) type { return formatBuf("0B", options, writer); } // The worst case in terms of space needed is 32 bytes + 3 for the suffix. - var buf: [35]u8 = undefined; - var bufstream = io.fixedBufferStream(buf[0..]); + var buf: [ryu128.min_buffer_size + 3]u8 = undefined; const mags_si = " kMGTPEZY"; const mags_iec = " KMGTPEZY"; @@ -905,20 +904,27 @@ fn formatSizeImpl(comptime base: comptime_int) type { else => unreachable, }; - formatFloatDecimal(new_value, options, bufstream.writer()) catch |err| switch (err) { - error.NoSpaceLeft => unreachable, // 35 bytes should be enough + const s = ryu128.format(&buf, new_value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) { + error.BufferTooSmall => unreachable, }; - bufstream.writer().writeAll(if (suffix == ' ') - "B" - else switch (base) { - 1000 => &[_]u8{ suffix, 'B' }, - 1024 => &[_]u8{ suffix, 'i', 'B' }, + var i: usize = s.len; + if (suffix == ' ') { + buf[i] = 'B'; + i += 1; + } else switch (base) { + 1000 => { + buf[i..][0..2].* = [_]u8{ suffix, 'B' }; + i += 2; + }, + 1024 => { + buf[i..][0..3].* = [_]u8{ suffix, 'i', 'B' }; + i += 3; + }, else => unreachable, - }) catch |err| switch (err) { - error.NoSpaceLeft => unreachable, - }; - return formatBuf(bufstream.getWritten(), options, writer); + } + + return formatBuf(buf[0..i], options, writer); } }; } @@ -1028,102 +1034,6 @@ pub fn formatBuf( } } -/// Print a float in scientific notation to the specified precision. Null uses full precision. -/// For floats with less than 64 bits, it should be the case that every full precision, printed -/// value can be re-parsed back to the same type unambiguously. -/// -/// Floats with more than 64 are currently rounded, see https://github.com/ziglang/zig/issues/1181 -pub fn formatFloatScientific( - value: anytype, - options: FormatOptions, - writer: anytype, -) !void { - var x = @as(f64, @floatCast(value)); - - // Errol doesn't handle these special cases. - if (math.signbit(x)) { - try writer.writeAll("-"); - x = -x; - } - - if (math.isNan(x)) { - return writer.writeAll("nan"); - } - if (math.isPositiveInf(x)) { - return writer.writeAll("inf"); - } - if (x == 0.0) { - try writer.writeAll("0"); - - if (options.precision) |precision| { - if (precision != 0) { - try writer.writeAll("."); - var i: usize = 0; - while (i < precision) : (i += 1) { - try writer.writeAll("0"); - } - } - } else { - try writer.writeAll(".0"); - } - - try writer.writeAll("e+00"); - return; - } - - var buffer: [32]u8 = undefined; - var float_decimal = errol.errol3(x, buffer[0..]); - - if (options.precision) |precision| { - errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Scientific); - - try writer.writeAll(float_decimal.digits[0..1]); - - // {e0} case prints no `.` - if (precision != 0) { - try writer.writeAll("."); - - var printed: usize = 0; - if (float_decimal.digits.len > 1) { - const num_digits = @min(float_decimal.digits.len, precision + 1); - try writer.writeAll(float_decimal.digits[1..num_digits]); - printed += num_digits - 1; - } - - while (printed < precision) : (printed += 1) { - try writer.writeAll("0"); - } - } - } else { - try writer.writeAll(float_decimal.digits[0..1]); - try writer.writeAll("."); - if (float_decimal.digits.len > 1) { - const num_digits = if (@TypeOf(value) == f32) @min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; - - try writer.writeAll(float_decimal.digits[1..num_digits]); - } else { - try writer.writeAll("0"); - } - } - - try writer.writeAll("e"); - const exp = float_decimal.exp - 1; - - if (exp >= 0) { - try writer.writeAll("+"); - if (exp > -10 and exp < 10) { - try writer.writeAll("0"); - } - try formatInt(exp, 10, .lower, FormatOptions{ .width = 0 }, writer); - } else { - try writer.writeAll("-"); - if (exp > -10 and exp < 10) { - try writer.writeAll("0"); - } - try formatInt(-exp, 10, .lower, FormatOptions{ .width = 0 }, writer); - } -} - pub fn formatFloatHexadecimal( value: anytype, options: FormatOptions, @@ -1233,149 +1143,6 @@ pub fn formatFloatHexadecimal( try formatInt(exponent - exponent_bias, 10, .lower, .{}, writer); } -/// Print a float of the format x.yyyyy where the number of y is specified by the precision argument. -/// By default floats are printed at full precision (no rounding). -/// -/// Floats with more than 64 bits are not yet supported, see https://github.com/ziglang/zig/issues/1181 -pub fn formatFloatDecimal( - value: anytype, - options: FormatOptions, - writer: anytype, -) !void { - var x = @as(f64, value); - - // Errol doesn't handle these special cases. - if (math.signbit(x)) { - try writer.writeAll("-"); - x = -x; - } - - if (math.isNan(x)) { - return writer.writeAll("nan"); - } - if (math.isPositiveInf(x)) { - return writer.writeAll("inf"); - } - if (x == 0.0) { - try writer.writeAll("0"); - - if (options.precision) |precision| { - if (precision != 0) { - try writer.writeAll("."); - var i: usize = 0; - while (i < precision) : (i += 1) { - try writer.writeAll("0"); - } - } - } - - return; - } - - // non-special case, use errol3 - var buffer: [32]u8 = undefined; - var float_decimal = errol.errol3(x, buffer[0..]); - - if (options.precision) |precision| { - errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal); - - // exp < 0 means the leading is always 0 as errol result is normalized. - const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; - - // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. - const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); - - if (num_digits_whole > 0) { - // We may have to zero pad, for instance 1e4 requires zero padding. - try writer.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]); - - var i: usize = num_digits_whole_no_pad; - while (i < num_digits_whole) : (i += 1) { - try writer.writeAll("0"); - } - } else { - try writer.writeAll("0"); - } - - // {.0} special case doesn't want a trailing '.' - if (precision == 0) { - return; - } - - try writer.writeAll("."); - - // Keep track of fractional count printed for case where we pre-pad then post-pad with 0's. - var printed: usize = 0; - - // Zero-fill until we reach significant digits or run out of precision. - if (float_decimal.exp <= 0) { - const zero_digit_count = @as(usize, @intCast(-float_decimal.exp)); - const zeros_to_print = @min(zero_digit_count, precision); - - var i: usize = 0; - while (i < zeros_to_print) : (i += 1) { - try writer.writeAll("0"); - printed += 1; - } - - if (printed >= precision) { - return; - } - } - - // Remaining fractional portion, zero-padding if insufficient. - assert(precision >= printed); - if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) { - try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]); - return; - } else { - try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad..]); - printed += float_decimal.digits.len - num_digits_whole_no_pad; - - while (printed < precision) : (printed += 1) { - try writer.writeAll("0"); - } - } - } else { - // exp < 0 means the leading is always 0 as errol result is normalized. - const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0; - - // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this. - const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len); - - if (num_digits_whole > 0) { - // We may have to zero pad, for instance 1e4 requires zero padding. - try writer.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]); - - var i: usize = num_digits_whole_no_pad; - while (i < num_digits_whole) : (i += 1) { - try writer.writeAll("0"); - } - } else { - try writer.writeAll("0"); - } - - // Omit `.` if no fractional portion - if (float_decimal.exp >= 0 and num_digits_whole_no_pad == float_decimal.digits.len) { - return; - } - - try writer.writeAll("."); - - // Zero-fill until we reach significant digits or run out of precision. - if (float_decimal.exp < 0) { - const zero_digit_count = @as(usize, @intCast(-float_decimal.exp)); - - var i: usize = 0; - while (i < zero_digit_count) : (i += 1) { - try writer.writeAll("0"); - } - } - - try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad..]); - } -} - pub fn formatInt( value: anytype, base: u8, @@ -1451,7 +1218,7 @@ pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options } // Converts values in the range [0, 100) to a string. -fn digits2(value: usize) [2]u8 { +pub fn digits2(value: usize) [2]u8 { return ("0001020304050607080910111213141516171819" ++ "2021222324252627282930313233343536373839" ++ "4041424344454647484950515253545556575859" ++ @@ -2362,7 +2129,7 @@ test "struct" { // Tuples try expectFmt("{ }", "{}", .{.{}}); try expectFmt("{ -1 }", "{}", .{.{-1}}); - try expectFmt("{ -1, 42, 2.5e+04 }", "{}", .{.{ -1, 42, 0.25e5 }}); + try expectFmt("{ -1, 42, 2.5e4 }", "{}", .{.{ -1, 42, 0.25e5 }}); } test "enum" { @@ -2409,19 +2176,19 @@ test "non-exhaustive enum" { } test "float.scientific" { - try expectFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)}); - try expectFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)}); - try expectFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)}); + try expectFmt("f32: 1.34e0", "f32: {e}", .{@as(f32, 1.34)}); + try expectFmt("f32: 1.234e1", "f32: {e}", .{@as(f32, 12.34)}); + try expectFmt("f64: -1.234e11", "f64: {e}", .{@as(f64, -12.34e10)}); try expectFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)}); } test "float.scientific.precision" { try expectFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)}); - try expectFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 814313563))))}); - try expectFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1006632960))))}); - // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. + try expectFmt("f64: 1.00000e-9", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 814313563))))}); + try expectFmt("f64: 7.81250e-3", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1006632960))))}); + // libc rounds 1.000005e5 to 1.00000e5 but zig does 1.00001e5. // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. - try expectFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1203982400))))}); + try expectFmt("f64: 1.00001e5", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1203982400))))}); } test "float.special" { @@ -2490,7 +2257,7 @@ test "float.hexadecimal.precision" { } test "float.decimal" { - try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)}); + try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e29)}); try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)}); try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)}); try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)}); @@ -2703,10 +2470,10 @@ test "formatFloatValue with comptime_float" { var buf: [20]u8 = undefined; var fbs = std.io.fixedBufferStream(&buf); try formatFloatValue(value, "", FormatOptions{}, fbs.writer()); - try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00")); + try std.testing.expectEqualStrings(fbs.getWritten(), "1e0"); - try expectFmt("1.0e+00", "{}", .{value}); - try expectFmt("1.0e+00", "{}", .{1.0}); + try expectFmt("1e0", "{}", .{value}); + try expectFmt("1e0", "{}", .{1.0}); } test "formatType max_depth" { @@ -2843,16 +2610,16 @@ test "padding fill char utf" { test "decimal float padding" { const number: f32 = 3.1415; - try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number}); - try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number}); - try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number}); + try expectFmt("left-pad: **3.142\n", "left-pad: {d:*>7.3}\n", .{number}); + try expectFmt("center-pad: *3.142*\n", "center-pad: {d:*^7.3}\n", .{number}); + try expectFmt("right-pad: 3.142**\n", "right-pad: {d:*<7.3}\n", .{number}); } test "sci float padding" { const number: f32 = 3.1415; - try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number}); - try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number}); - try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number}); + try expectFmt("left-pad: ****3.142e0\n", "left-pad: {e:*>11.3}\n", .{number}); + try expectFmt("center-pad: **3.142e0**\n", "center-pad: {e:*^11.3}\n", .{number}); + try expectFmt("right-pad: 3.142e0****\n", "right-pad: {e:*<11.3}\n", .{number}); } test "null" { @@ -2883,8 +2650,8 @@ test "runtime width specifier" { test "runtime precision specifier" { const number: f32 = 3.1415; const precision: usize = 2; - try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision }); - try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision }); + try expectFmt("3.14e0", "{:1.[1]}", .{ number, precision }); + try expectFmt("3.14e0", "{:1.[precision]}", .{ .number = number, .precision = precision }); } test "recursive format function" { diff --git a/lib/std/fmt/errol.zig b/lib/std/fmt/errol.zig deleted file mode 100644 index 760ebca786e2..000000000000 --- a/lib/std/fmt/errol.zig +++ /dev/null @@ -1,709 +0,0 @@ -const std = @import("../std.zig"); -const enum3 = @import("errol/enum3.zig").enum3; -const enum3_data = @import("errol/enum3.zig").enum3_data; -const lookup_table = @import("errol/lookup.zig").lookup_table; -const HP = @import("errol/lookup.zig").HP; -const math = std.math; -const mem = std.mem; -const assert = std.debug.assert; - -pub const FloatDecimal = struct { - digits: []u8, - exp: i32, -}; - -pub const RoundMode = enum { - // Round only the fractional portion (e.g. 1234.23 has precision 2) - Decimal, - // Round the entire whole/fractional portion (e.g. 1.23423e3 has precision 5) - Scientific, -}; - -/// Round a FloatDecimal as returned by errol3 to the specified fractional precision. -/// All digits after the specified precision should be considered invalid. -pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: RoundMode) void { - // The round digit refers to the index which we should look at to determine - // whether we need to round to match the specified precision. - var round_digit: usize = 0; - - switch (mode) { - RoundMode.Decimal => { - if (float_decimal.exp >= 0) { - round_digit = precision + @as(usize, @intCast(float_decimal.exp)); - } else { - // if a small negative exp, then adjust we need to offset by the number - // of leading zeros that will occur. - const min_exp_required = @as(usize, @intCast(-float_decimal.exp)); - if (precision > min_exp_required) { - round_digit = precision - min_exp_required; - } - } - }, - RoundMode.Scientific => { - round_digit = 1 + precision; - }, - } - - // It suffices to look at just this digit. We don't round and propagate say 0.04999 to 0.05 - // first, and then to 0.1 in the case of a {.1} single precision. - - // Find the digit which will signify the round point and start rounding backwards. - if (round_digit < float_decimal.digits.len and float_decimal.digits[round_digit] - '0' >= 5) { - assert(round_digit >= 0); - - var i = round_digit; - while (true) { - if (i == 0) { - // Rounded all the way past the start. This was of the form 9.999... - // Slot the new digit in place and increase the exponent. - float_decimal.exp += 1; - - // Re-size the buffer to use the reserved leading byte. - const one_before = @as([*]u8, @ptrFromInt(@intFromPtr(&float_decimal.digits[0]) - 1)); - float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1]; - float_decimal.digits[0] = '1'; - return; - } - - i -= 1; - - const new_value = (float_decimal.digits[i] - '0' + 1) % 10; - float_decimal.digits[i] = new_value + '0'; - - // must continue rounding until non-9 - if (new_value != 0) { - return; - } - } - } -} - -/// Corrected Errol3 double to ASCII conversion. -pub fn errol3(value: f64, buffer: []u8) FloatDecimal { - const bits = @as(u64, @bitCast(value)); - const i = tableLowerBound(bits); - if (i < enum3.len and enum3[i] == bits) { - const data = enum3_data[i]; - const digits = buffer[1..][0..data.str.len]; - @memcpy(digits, data.str); - return FloatDecimal{ - .digits = digits, - .exp = data.exp, - }; - } - - // We generate digits starting at index 1. If rounding a buffer later then it may be - // required to generate a preceding digit in some cases (9.999) in which case we use - // the 0-index for this extra digit. - return errol3u(value, buffer[1..]); -} - -/// Uncorrected Errol3 double to ASCII conversion. -fn errol3u(val: f64, buffer: []u8) FloatDecimal { - // check if in integer or fixed range - if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) { - return errolInt(val, buffer); - } else if (val >= 16.0 and val < 9.007199254740992e15) { - return errolFixed(val, buffer); - } - return errolSlow(val, buffer); -} - -fn errolSlow(val: f64, buffer: []u8) FloatDecimal { - // normalize the midpoint - - const e = math.frexp(val).exponent; - var exp = @as(i16, @intFromFloat(@floor(307 + @as(f64, @floatFromInt(e)) * 0.30103))); - if (exp < 20) { - exp = 20; - } else if (@as(usize, @intCast(exp)) >= lookup_table.len) { - exp = @as(i16, @intCast(lookup_table.len - 1)); - } - - var mid = lookup_table[@as(usize, @intCast(exp))]; - mid = hpProd(mid, val); - const lten = lookup_table[@as(usize, @intCast(exp))].val; - - exp -= 307; - - var ten: f64 = 1.0; - - while (mid.val > 10.0 or (mid.val == 10.0 and mid.off >= 0.0)) { - exp += 1; - hpDiv10(&mid); - ten /= 10.0; - } - - while (mid.val < 1.0 or (mid.val == 1.0 and mid.off < 0.0)) { - exp -= 1; - hpMul10(&mid); - ten *= 10.0; - } - - // compute boundaries - var high = HP{ - .val = mid.val, - .off = mid.off + (fpnext(val) - val) * lten * ten / 2.0, - }; - var low = HP{ - .val = mid.val, - .off = mid.off + (fpprev(val) - val) * lten * ten / 2.0, - }; - - hpNormalize(&high); - hpNormalize(&low); - - // normalized boundaries - - while (high.val > 10.0 or (high.val == 10.0 and high.off >= 0.0)) { - exp += 1; - hpDiv10(&high); - hpDiv10(&low); - } - - while (high.val < 1.0 or (high.val == 1.0 and high.off < 0.0)) { - exp -= 1; - hpMul10(&high); - hpMul10(&low); - } - - // digit generation - var buf_index: usize = 0; - const bound = buffer.len - 1; - while (buf_index < bound) { - var hdig = @as(u8, @intFromFloat(@floor(high.val))); - if ((high.val == @as(f64, @floatFromInt(hdig))) and (high.off < 0)) hdig -= 1; - - var ldig = @as(u8, @intFromFloat(@floor(low.val))); - if ((low.val == @as(f64, @floatFromInt(ldig))) and (low.off < 0)) ldig -= 1; - - if (ldig != hdig) break; - - buffer[buf_index] = hdig + '0'; - buf_index += 1; - high.val -= @as(f64, @floatFromInt(hdig)); - low.val -= @as(f64, @floatFromInt(ldig)); - hpMul10(&high); - hpMul10(&low); - } - - const tmp = (high.val + low.val) / 2.0; - var mdig = @as(u8, @intFromFloat(@floor(tmp + 0.5))); - if ((@as(f64, @floatFromInt(mdig)) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1; - - buffer[buf_index] = mdig + '0'; - buf_index += 1; - - return FloatDecimal{ - .digits = buffer[0..buf_index], - .exp = exp, - }; -} - -fn tableLowerBound(k: u64) usize { - var i = enum3.len; - var j: usize = 0; - - while (j < enum3.len) { - if (enum3[j] < k) { - j = 2 * j + 2; - } else { - i = j; - j = 2 * j + 1; - } - } - - return i; -} - -/// Compute the product of an HP number and a double. -/// @in: The HP number. -/// @val: The double. -/// &returns: The HP number. -fn hpProd(in: HP, val: f64) HP { - var hi: f64 = undefined; - var lo: f64 = undefined; - split(in.val, &hi, &lo); - - var hi2: f64 = undefined; - var lo2: f64 = undefined; - split(val, &hi2, &lo2); - - const p = in.val * val; - const e = ((hi * hi2 - p) + lo * hi2 + hi * lo2) + lo * lo2; - - return HP{ - .val = p, - .off = in.off * val + e, - }; -} - -/// Split a double into two halves. -/// @val: The double. -/// @hi: The high bits. -/// @lo: The low bits. -fn split(val: f64, hi: *f64, lo: *f64) void { - hi.* = gethi(val); - lo.* = val - hi.*; -} - -fn gethi(in: f64) f64 { - const bits = @as(u64, @bitCast(in)); - const new_bits = bits & 0xFFFFFFFFF8000000; - return @as(f64, @bitCast(new_bits)); -} - -/// Normalize the number by factoring in the error. -/// @hp: The float pair. -fn hpNormalize(hp: *HP) void { - const val = hp.val; - hp.val += hp.off; - hp.off += val - hp.val; -} - -/// Divide the high-precision number by ten. -/// @hp: The high-precision number -fn hpDiv10(hp: *HP) void { - var val = hp.val; - - hp.val /= 10.0; - hp.off /= 10.0; - - val -= hp.val * 8.0; - val -= hp.val * 2.0; - - hp.off += val / 10.0; - - hpNormalize(hp); -} - -/// Multiply the high-precision number by ten. -/// @hp: The high-precision number -fn hpMul10(hp: *HP) void { - const val = hp.val; - - hp.val *= 10.0; - hp.off *= 10.0; - - var off = hp.val; - off -= val * 8.0; - off -= val * 2.0; - - hp.off -= off; - - hpNormalize(hp); -} - -/// Integer conversion algorithm, guaranteed correct, optimal, and best. -/// @val: The val. -/// @buf: The output buffer. -/// &return: The exponent. -fn errolInt(val: f64, buffer: []u8) FloatDecimal { - const pow19 = @as(u128, 1e19); - - assert((val > 9.007199254740992e15) and val < (3.40282366920938e38)); - - var mid = @as(u128, @intFromFloat(val)); - var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0); - var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0); - - if (@as(u64, @bitCast(val)) & 0x1 != 0) { - high -= 1; - } else { - low -= 1; - } - - var l64 = @as(u64, @intCast(low % pow19)); - const lf = @as(u64, @intCast((low / pow19) % pow19)); - - var h64 = @as(u64, @intCast(high % pow19)); - const hf = @as(u64, @intCast((high / pow19) % pow19)); - - if (lf != hf) { - l64 = lf; - h64 = hf; - mid = mid / (pow19 / 10); - } - - var mi: i32 = mismatch10(l64, h64); - var x: u64 = 1; - { - var i: i32 = @intFromBool(lf == hf); - while (i < mi) : (i += 1) { - x *= 10; - } - } - const m64 = @as(u64, @truncate(@divTrunc(mid, x))); - - if (lf != hf) mi += 19; - - var buf_index = u64toa(m64, buffer) - 1; - - if (mi != 0) { - const round_up = buffer[buf_index] >= '5'; - if (buf_index == 0 or (round_up and buffer[buf_index - 1] == '9')) return errolSlow(val, buffer); - buffer[buf_index - 1] += @intFromBool(round_up); - } else { - buf_index += 1; - } - - return FloatDecimal{ - .digits = buffer[0..buf_index], - .exp = @as(i32, @intCast(buf_index)) + mi, - }; -} - -/// Fixed point conversion algorithm, guaranteed correct, optimal, and best. -/// @val: The val. -/// @buf: The output buffer. -/// &return: The exponent. -fn errolFixed(val: f64, buffer: []u8) FloatDecimal { - assert((val >= 16.0) and (val < 9.007199254740992e15)); - - const u = @as(u64, @intFromFloat(val)); - const n = @as(f64, @floatFromInt(u)); - - var mid = val - n; - var lo = ((fpprev(val) - n) + mid) / 2.0; - var hi = ((fpnext(val) - n) + mid) / 2.0; - - const buf_index = u64toa(u, buffer); - const exp: i32 = @intCast(buf_index); - var j = buf_index; - buffer[j] = 0; - - if (mid != 0.0) { - while (mid != 0.0) { - lo *= 10.0; - const ldig = @as(i32, @intFromFloat(lo)); - lo -= @as(f64, @floatFromInt(ldig)); - - mid *= 10.0; - const mdig = @as(i32, @intFromFloat(mid)); - mid -= @as(f64, @floatFromInt(mdig)); - - hi *= 10.0; - const hdig = @as(i32, @intFromFloat(hi)); - hi -= @as(f64, @floatFromInt(hdig)); - - buffer[j] = @as(u8, @intCast(mdig + '0')); - j += 1; - - if (hdig != ldig or j > 50) break; - } - - if (mid > 0.5) { - buffer[j - 1] += 1; - } else if ((mid == 0.5) and (buffer[j - 1] & 0x1) != 0) { - buffer[j - 1] += 1; - } - } else { - while (buffer[j - 1] == '0') { - buffer[j - 1] = 0; - j -= 1; - } - } - - buffer[j] = 0; - - return FloatDecimal{ - .digits = buffer[0..j], - .exp = exp, - }; -} - -fn fpnext(val: f64) f64 { - return @as(f64, @bitCast(@as(u64, @bitCast(val)) +% 1)); -} - -fn fpprev(val: f64) f64 { - return @as(f64, @bitCast(@as(u64, @bitCast(val)) -% 1)); -} - -pub const c_digits_lut = [_]u8{ - '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', - '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', - '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', - '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', - '2', '8', '2', '9', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', - '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '4', '0', '4', '1', - '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', - '4', '9', '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', - '5', '6', '5', '7', '5', '8', '5', '9', '6', '0', '6', '1', '6', '2', - '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', - '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', - '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', '2', '8', '3', - '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '9', '0', - '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', - '9', '8', '9', '9', -}; - -fn u64toa(value_param: u64, buffer: []u8) usize { - var value = value_param; - const kTen8: u64 = 100000000; - const kTen9: u64 = kTen8 * 10; - const kTen10: u64 = kTen8 * 100; - const kTen11: u64 = kTen8 * 1000; - const kTen12: u64 = kTen8 * 10000; - const kTen13: u64 = kTen8 * 100000; - const kTen14: u64 = kTen8 * 1000000; - const kTen15: u64 = kTen8 * 10000000; - const kTen16: u64 = kTen8 * kTen8; - - var buf_index: usize = 0; - - if (value < kTen8) { - const v = @as(u32, @intCast(value)); - if (v < 10000) { - const d1: u32 = (v / 100) << 1; - const d2: u32 = (v % 100) << 1; - - if (v >= 1000) { - buffer[buf_index] = c_digits_lut[d1]; - buf_index += 1; - } - if (v >= 100) { - buffer[buf_index] = c_digits_lut[d1 + 1]; - buf_index += 1; - } - if (v >= 10) { - buffer[buf_index] = c_digits_lut[d2]; - buf_index += 1; - } - buffer[buf_index] = c_digits_lut[d2 + 1]; - buf_index += 1; - } else { - // value = bbbbcccc - const b: u32 = v / 10000; - const c: u32 = v % 10000; - - const d1: u32 = (b / 100) << 1; - const d2: u32 = (b % 100) << 1; - - const d3: u32 = (c / 100) << 1; - const d4: u32 = (c % 100) << 1; - - if (value >= 10000000) { - buffer[buf_index] = c_digits_lut[d1]; - buf_index += 1; - } - if (value >= 1000000) { - buffer[buf_index] = c_digits_lut[d1 + 1]; - buf_index += 1; - } - if (value >= 100000) { - buffer[buf_index] = c_digits_lut[d2]; - buf_index += 1; - } - buffer[buf_index] = c_digits_lut[d2 + 1]; - buf_index += 1; - - buffer[buf_index] = c_digits_lut[d3]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d3 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d4]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d4 + 1]; - buf_index += 1; - } - } else if (value < kTen16) { - const v0: u32 = @as(u32, @intCast(value / kTen8)); - const v1: u32 = @as(u32, @intCast(value % kTen8)); - - const b0: u32 = v0 / 10000; - const c0: u32 = v0 % 10000; - - const d1: u32 = (b0 / 100) << 1; - const d2: u32 = (b0 % 100) << 1; - - const d3: u32 = (c0 / 100) << 1; - const d4: u32 = (c0 % 100) << 1; - - const b1: u32 = v1 / 10000; - const c1: u32 = v1 % 10000; - - const d5: u32 = (b1 / 100) << 1; - const d6: u32 = (b1 % 100) << 1; - - const d7: u32 = (c1 / 100) << 1; - const d8: u32 = (c1 % 100) << 1; - - if (value >= kTen15) { - buffer[buf_index] = c_digits_lut[d1]; - buf_index += 1; - } - if (value >= kTen14) { - buffer[buf_index] = c_digits_lut[d1 + 1]; - buf_index += 1; - } - if (value >= kTen13) { - buffer[buf_index] = c_digits_lut[d2]; - buf_index += 1; - } - if (value >= kTen12) { - buffer[buf_index] = c_digits_lut[d2 + 1]; - buf_index += 1; - } - if (value >= kTen11) { - buffer[buf_index] = c_digits_lut[d3]; - buf_index += 1; - } - if (value >= kTen10) { - buffer[buf_index] = c_digits_lut[d3 + 1]; - buf_index += 1; - } - if (value >= kTen9) { - buffer[buf_index] = c_digits_lut[d4]; - buf_index += 1; - } - if (value >= kTen8) { - buffer[buf_index] = c_digits_lut[d4 + 1]; - buf_index += 1; - } - - buffer[buf_index] = c_digits_lut[d5]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d5 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d6]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d6 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d7]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d7 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d8]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d8 + 1]; - buf_index += 1; - } else { - const a = @as(u32, @intCast(value / kTen16)); // 1 to 1844 - value %= kTen16; - - if (a < 10) { - buffer[buf_index] = '0' + @as(u8, @intCast(a)); - buf_index += 1; - } else if (a < 100) { - const i: u32 = a << 1; - buffer[buf_index] = c_digits_lut[i]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[i + 1]; - buf_index += 1; - } else if (a < 1000) { - buffer[buf_index] = '0' + @as(u8, @intCast(a / 100)); - buf_index += 1; - - const i: u32 = (a % 100) << 1; - buffer[buf_index] = c_digits_lut[i]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[i + 1]; - buf_index += 1; - } else { - const i: u32 = (a / 100) << 1; - const j: u32 = (a % 100) << 1; - buffer[buf_index] = c_digits_lut[i]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[i + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[j]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[j + 1]; - buf_index += 1; - } - - const v0 = @as(u32, @intCast(value / kTen8)); - const v1 = @as(u32, @intCast(value % kTen8)); - - const b0: u32 = v0 / 10000; - const c0: u32 = v0 % 10000; - - const d1: u32 = (b0 / 100) << 1; - const d2: u32 = (b0 % 100) << 1; - - const d3: u32 = (c0 / 100) << 1; - const d4: u32 = (c0 % 100) << 1; - - const b1: u32 = v1 / 10000; - const c1: u32 = v1 % 10000; - - const d5: u32 = (b1 / 100) << 1; - const d6: u32 = (b1 % 100) << 1; - - const d7: u32 = (c1 / 100) << 1; - const d8: u32 = (c1 % 100) << 1; - - buffer[buf_index] = c_digits_lut[d1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d1 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d2]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d2 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d3]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d3 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d4]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d4 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d5]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d5 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d6]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d6 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d7]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d7 + 1]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d8]; - buf_index += 1; - buffer[buf_index] = c_digits_lut[d8 + 1]; - buf_index += 1; - } - - return buf_index; -} - -fn fpeint(from: f64) u128 { - const bits = @as(u64, @bitCast(from)); - assert((bits & ((1 << 52) - 1)) == 0); - - return @as(u128, 1) << @as(u7, @truncate((bits >> 52) -% 1023)); -} - -/// Given two different integers with the same length in terms of the number -/// of decimal digits, index the digits from the right-most position starting -/// from zero, find the first index where the digits in the two integers -/// divergent starting from the highest index. -/// @a: Integer a. -/// @b: Integer b. -/// &returns: An index within [0, 19). -fn mismatch10(a: u64, b: u64) i32 { - const pow10 = 10000000000; - const af = a / pow10; - const bf = b / pow10; - - var i: i32 = 0; - var a_copy = a; - var b_copy = b; - - if (af != bf) { - i = 10; - a_copy = af; - b_copy = bf; - } - - while (true) : (i += 1) { - a_copy /= 10; - b_copy /= 10; - - if (a_copy == b_copy) return i; - } -} diff --git a/lib/std/fmt/errol/enum3.zig b/lib/std/fmt/errol/enum3.zig deleted file mode 100644 index c27753483d16..000000000000 --- a/lib/std/fmt/errol/enum3.zig +++ /dev/null @@ -1,881 +0,0 @@ -pub const enum3 = [_]u64{ - 0x4e2e2785c3a2a20b, - 0x240a28877a09a4e1, - 0x728fca36c06cf106, - 0x1016b100e18e5c17, - 0x3159190e30e46c1d, - 0x64312a13daa46fe4, - 0x7c41926c7a7122ba, - 0x08667a3c8dc4bc9c, - 0x18dde996371c6060, - 0x297c2c31a31998ae, - 0x368b870de5d93270, - 0x57d561def4a9ee32, - 0x6d275d226331d03a, - 0x76703d7cb98edc59, - 0x7ec490abad057752, - 0x037be9d5a60850b5, - 0x0c63165633977bca, - 0x14a048cb468bc209, - 0x20dc29bc6879dfcd, - 0x2643dc6227de9148, - 0x2d64f14348a4c5db, - 0x341eef5e1f90ac35, - 0x4931159a8bd8a240, - 0x503ca9bade45b94a, - 0x5c1af5b5378aa2e5, - 0x6b4ef9beaa7aa584, - 0x6ef1c382c3819a0a, - 0x754fe46e378bf133, - 0x7ace779fddf21622, - 0x7df22815078cb97b, - 0x7f33c8eeb77b8d05, - 0x011b7aa3d73f6658, - 0x06ceb7f2c53db97f, - 0x0b8f3d82e9356287, - 0x0e304273b18918b0, - 0x139fb24e492936f6, - 0x176090684f5fe997, - 0x1e3035e7b5183922, - 0x220ce77c2b3328fc, - 0x246441ed79830182, - 0x279b5cd8bbdd8770, - 0x2cc7c3fba45c1272, - 0x3081eab25ad0fcf7, - 0x329f5a18504dfaac, - 0x347eef5e1f90ac35, - 0x3a978cfcab31064c, - 0x4baa32ac316fb3ab, - 0x4eb9a2c2a34ac2f9, - 0x522f6a5025e71a61, - 0x5935ede8cce30845, - 0x5f9aeac2d1ea2695, - 0x6820ee7811241ad3, - 0x6c06c9e14b7c22c3, - 0x6e5a2fbffdb7580c, - 0x71160cf8f38b0465, - 0x738a37935f3b71c9, - 0x756fe46e378bf133, - 0x7856d2aa2fc5f2b5, - 0x7bd3b063946e10ae, - 0x7d8220e1772428d7, - 0x7e222815078cb97b, - 0x7ef5bc471d5456c7, - 0x7fb82baa4ae611dc, - 0x00bb7aa3d73f6658, - 0x0190a0f3c55062c5, - 0x05898e3445512a6e, - 0x07bfe89cf1bd76ac, - 0x08dfa7ebe304ee3e, - 0x0c43165633977bca, - 0x0e104273b18918b0, - 0x0fd6ba8608faa6a9, - 0x10b4139a6b17b224, - 0x1466cc4fc92a0fa6, - 0x162ba6008389068a, - 0x1804116d591ef1fb, - 0x1c513770474911bd, - 0x1e7035e7b5183923, - 0x2114dab846e19e25, - 0x222ce77c2b3328fc, - 0x244441ed79830182, - 0x249b23b50fc204db, - 0x278aacfcb88c92d6, - 0x289d52af46e5fa6a, - 0x2bdec922478c0421, - 0x2d44f14348a4c5dc, - 0x2f0c1249e96b6d8d, - 0x30addc7e975c5045, - 0x322aedaa0fc32ac8, - 0x33deef5e1f90ac34, - 0x343eef5e1f90ac35, - 0x35ef1de1f7f14439, - 0x3854faba79ea92ec, - 0x47f52d02c7e14af7, - 0x4a6bb6979ae39c49, - 0x4c85564fb098c955, - 0x4e80fde34c996086, - 0x4ed9a2c2a34ac2f9, - 0x51a3274280201a89, - 0x574fe0403124a00e, - 0x581561def4a9ee31, - 0x5b55ed1f039cebff, - 0x5e2780695036a679, - 0x624be064a3fb2725, - 0x674dcfee6690ffc6, - 0x6a6cc08102f0da5b, - 0x6be6c9e14b7c22c4, - 0x6ce75d226331d03a, - 0x6d5b9445072f4374, - 0x6e927edd0dbb8c09, - 0x71060cf8f38b0465, - 0x71b1d7cb7eae05d9, - 0x72fba10d818fdafd, - 0x739a37935f3b71c9, - 0x755fe46e378bf133, - 0x76603d7cb98edc59, - 0x78447e17e7814ce7, - 0x799d696737fe68c7, - 0x7ade779fddf21622, - 0x7c1c283ffc61c87d, - 0x7d1a85c6f7fba05d, - 0x7da220e1772428d7, - 0x7e022815078cb97b, - 0x7e9a9b45a91f1700, - 0x7ee3c8eeb77b8d05, - 0x7f13c8eeb77b8d05, - 0x7f6594223f5654bf, - 0x7fd82baa4ae611dc, - 0x002d243f646eaf51, - 0x00f5d15b26b80e30, - 0x0180a0f3c55062c5, - 0x01f393b456eef178, - 0x05798e3445512a6e, - 0x06afdadafcacdf85, - 0x06e8b03fd6894b66, - 0x07cfe89cf1bd76ac, - 0x08ac25584881552a, - 0x097822507db6a8fd, - 0x0c27b35936d56e28, - 0x0c53165633977bca, - 0x0c8e9eddbbb259b4, - 0x0e204273b18918b0, - 0x0f1d16d6d4b89689, - 0x0fe6ba8608faa6a9, - 0x105f48347c60a1be, - 0x13627383c5456c5e, - 0x13f93bb1e72a2033, - 0x148048cb468bc208, - 0x1514c0b3a63c1444, - 0x175090684f5fe997, - 0x17e4116d591ef1fb, - 0x18cde996371c6060, - 0x19aa2cf604c30d3f, - 0x1d2b1ad9101b1bfd, - 0x1e5035e7b5183923, - 0x1fe5a79c4e71d028, - 0x20ec29bc6879dfcd, - 0x218ce77c2b3328fb, - 0x221ce77c2b3328fc, - 0x233f346f9ed36b89, - 0x243441ed79830182, - 0x245441ed79830182, - 0x247441ed79830182, - 0x2541e4ee41180c0a, - 0x277aacfcb88c92d6, - 0x279aacfcb88c92d6, - 0x27cbb4c6bd8601bd, - 0x28c04a616046e074, - 0x2a4eeff57768f88c, - 0x2c2379f099a86227, - 0x2d04f14348a4c5db, - 0x2d54f14348a4c5dc, - 0x2d6a8c931c19b77a, - 0x2fa387cf9cb4ad4e, - 0x308ddc7e975c5046, - 0x3149190e30e46c1d, - 0x318d2ec75df6ba2a, - 0x32548050091c3c24, - 0x33beef5e1f90ac34, - 0x33feef5e1f90ac35, - 0x342eef5e1f90ac35, - 0x345eef5e1f90ac35, - 0x35108621c4199208, - 0x366b870de5d93270, - 0x375b20c2f4f8d4a0, - 0x3864faba79ea92ec, - 0x3aa78cfcab31064c, - 0x4919d9577de925d5, - 0x49ccadd6dd730c96, - 0x4b9a32ac316fb3ab, - 0x4bba32ac316fb3ab, - 0x4cff20b1a0d7f626, - 0x4e3e2785c3a2a20b, - 0x4ea9a2c2a34ac2f9, - 0x4ec9a2c2a34ac2f9, - 0x4f28750ea732fdae, - 0x513843e10734fa57, - 0x51e71760b3c0bc13, - 0x55693ba3249a8511, - 0x57763ae2caed4528, - 0x57f561def4a9ee32, - 0x584561def4a9ee31, - 0x5b45ed1f039cebfe, - 0x5bfaf5b5378aa2e5, - 0x5c6cf45d333da323, - 0x5e64ec8fd70420c7, - 0x6009813653f62db7, - 0x64112a13daa46fe4, - 0x672dcfee6690ffc6, - 0x677a77581053543b, - 0x699873e3758bc6b3, - 0x6b3ef9beaa7aa584, - 0x6b7b86d8c3df7cd1, - 0x6bf6c9e14b7c22c3, - 0x6c16c9e14b7c22c3, - 0x6d075d226331d03a, - 0x6d5a3bdac4f00f33, - 0x6e4a2fbffdb7580c, - 0x6e927edd0dbb8c08, - 0x6ee1c382c3819a0a, - 0x70f60cf8f38b0465, - 0x7114390c68b888ce, - 0x714fb4840532a9e5, - 0x727fca36c06cf106, - 0x72eba10d818fdafd, - 0x737a37935f3b71c9, - 0x73972852443155ae, - 0x754fe46e378bf132, - 0x755fe46e378bf132, - 0x756fe46e378bf132, - 0x76603d7cb98edc58, - 0x76703d7cb98edc58, - 0x782f7c6a9ad432a1, - 0x78547e17e7814ce7, - 0x7964066d88c7cab8, - 0x7ace779fddf21621, - 0x7ade779fddf21621, - 0x7bc3b063946e10ae, - 0x7c0c283ffc61c87d, - 0x7c31926c7a7122ba, - 0x7d0a85c6f7fba05d, - 0x7d52a5daf9226f04, - 0x7d9220e1772428d7, - 0x7db220e1772428d7, - 0x7dfe5aceedf1c1f1, - 0x7e122815078cb97b, - 0x7e8a9b45a91f1700, - 0x7eb6202598194bee, - 0x7ec6202598194bee, - 0x7ef3c8eeb77b8d05, - 0x7f03c8eeb77b8d05, - 0x7f23c8eeb77b8d05, - 0x7f5594223f5654bf, - 0x7f9914e03c9260ee, - 0x7fc82baa4ae611dc, - 0x7fefffffffffffff, - 0x001d243f646eaf51, - 0x00ab7aa3d73f6658, - 0x00cb7aa3d73f6658, - 0x010b7aa3d73f6658, - 0x012b7aa3d73f6658, - 0x0180a0f3c55062c6, - 0x0190a0f3c55062c6, - 0x03719f08ccdccfe5, - 0x03dc25ba6a45de02, - 0x05798e3445512a6f, - 0x05898e3445512a6f, - 0x06bfdadafcacdf85, - 0x06cfdadafcacdf85, - 0x06f8b03fd6894b66, - 0x07c1707c02068785, - 0x08567a3c8dc4bc9c, - 0x089c25584881552a, - 0x08dfa7ebe304ee3d, - 0x096822507db6a8fd, - 0x09e41934d77659be, - 0x0c27b35936d56e27, - 0x0c43165633977bc9, - 0x0c53165633977bc9, - 0x0c63165633977bc9, - 0x0c7e9eddbbb259b4, - 0x0c9e9eddbbb259b4, - 0x0e104273b18918b1, - 0x0e204273b18918b1, - 0x0e304273b18918b1, - 0x0fd6ba8608faa6a8, - 0x0fe6ba8608faa6a8, - 0x1006b100e18e5c17, - 0x104f48347c60a1be, - 0x10a4139a6b17b224, - 0x12cb91d317c8ebe9, - 0x138fb24e492936f6, - 0x13afb24e492936f6, - 0x14093bb1e72a2033, - 0x1476cc4fc92a0fa6, - 0x149048cb468bc209, - 0x1504c0b3a63c1444, - 0x161ba6008389068a, - 0x168cfab1a09b49c4, - 0x175090684f5fe998, - 0x176090684f5fe998, - 0x17f4116d591ef1fb, - 0x18a710b7a2ef18b7, - 0x18d99fccca44882a, - 0x199a2cf604c30d3f, - 0x1b5ebddc6593c857, - 0x1d1b1ad9101b1bfd, - 0x1d3b1ad9101b1bfd, - 0x1e4035e7b5183923, - 0x1e6035e7b5183923, - 0x1fd5a79c4e71d028, - 0x20cc29bc6879dfcd, - 0x20e8823a57adbef8, - 0x2104dab846e19e25, - 0x2124dab846e19e25, - 0x220ce77c2b3328fb, - 0x221ce77c2b3328fb, - 0x222ce77c2b3328fb, - 0x229197b290631476, - 0x240a28877a09a4e0, - 0x243441ed79830181, - 0x244441ed79830181, - 0x245441ed79830181, - 0x246441ed79830181, - 0x247441ed79830181, - 0x248b23b50fc204db, - 0x24ab23b50fc204db, - 0x2633dc6227de9148, - 0x2653dc6227de9148, - 0x277aacfcb88c92d7, - 0x278aacfcb88c92d7, - 0x279aacfcb88c92d7, - 0x27bbb4c6bd8601bd, - 0x289d52af46e5fa69, - 0x28b04a616046e074, - 0x28d04a616046e074, - 0x2a3eeff57768f88c, - 0x2b8e3a0aeed7be19, - 0x2beec922478c0421, - 0x2cc7c3fba45c1271, - 0x2cf4f14348a4c5db, - 0x2d44f14348a4c5db, - 0x2d54f14348a4c5db, - 0x2d5a8c931c19b77a, - 0x2d64f14348a4c5dc, - 0x2efc1249e96b6d8d, - 0x2f0f6b23cfe98807, - 0x2fe91b9de4d5cf31, - 0x308ddc7e975c5045, - 0x309ddc7e975c5045, - 0x30bddc7e975c5045, - 0x3150ed9bd6bfd003, - 0x317d2ec75df6ba2a, - 0x321aedaa0fc32ac8, - 0x32448050091c3c24, - 0x328f5a18504dfaac, - 0x3336dca59d035820, - 0x33ceef5e1f90ac34, - 0x33eeef5e1f90ac35, - 0x340eef5e1f90ac35, - 0x34228f9edfbd3420, - 0x34328f9edfbd3420, - 0x344eef5e1f90ac35, - 0x346eef5e1f90ac35, - 0x35008621c4199208, - 0x35e0ac2e7f90b8a3, - 0x361dde4a4ab13e09, - 0x367b870de5d93270, - 0x375b20c2f4f8d49f, - 0x37f25d342b1e33e5, - 0x3854faba79ea92ed, - 0x3864faba79ea92ed, - 0x3a978cfcab31064d, - 0x3aa78cfcab31064d, - 0x490cd230a7ff47c3, - 0x4929d9577de925d5, - 0x4939d9577de925d5, - 0x49dcadd6dd730c96, - 0x4a7bb6979ae39c49, - 0x4b9a32ac316fb3ac, - 0x4baa32ac316fb3ac, - 0x4bba32ac316fb3ac, - 0x4cef20b1a0d7f626, - 0x4e2e2785c3a2a20a, - 0x4e3e2785c3a2a20a, - 0x4e6454b1aef62c8d, - 0x4e90fde34c996086, - 0x4ea9a2c2a34ac2fa, - 0x4eb9a2c2a34ac2fa, - 0x4ec9a2c2a34ac2fa, - 0x4ed9a2c2a34ac2fa, - 0x4f38750ea732fdae, - 0x504ca9bade45b94a, - 0x514843e10734fa57, - 0x51b3274280201a89, - 0x521f6a5025e71a61, - 0x52c6a47d4e7ec633, - 0x55793ba3249a8511, - 0x575fe0403124a00e, - 0x57863ae2caed4528, - 0x57e561def4a9ee32, - 0x580561def4a9ee31, - 0x582561def4a9ee31, - 0x585561def4a9ee31, - 0x59d0dd8f2788d699, - 0x5b55ed1f039cebfe, - 0x5beaf5b5378aa2e5, - 0x5c0af5b5378aa2e5, - 0x5c4ef3052ef0a361, - 0x5e1780695036a679, - 0x5e54ec8fd70420c7, - 0x5e6b5e2f86026f05, - 0x5faaeac2d1ea2695, - 0x611260322d04d50b, - 0x625be064a3fb2725, - 0x64212a13daa46fe4, - 0x671dcfee6690ffc6, - 0x673dcfee6690ffc6, - 0x675dcfee6690ffc6, - 0x678a77581053543b, - 0x682d3683fa3d1ee0, - 0x699cb490951e8515, - 0x6b3ef9beaa7aa583, - 0x6b4ef9beaa7aa583, - 0x6b7896beb0c66eb9, - 0x6bdf20938e7414bb, - 0x6bef20938e7414bb, - 0x6bf6c9e14b7c22c4, - 0x6c06c9e14b7c22c4, - 0x6c16c9e14b7c22c4, - 0x6cf75d226331d03a, - 0x6d175d226331d03a, - 0x6d4b9445072f4374, -}; - -const Slab = struct { - str: []const u8, - exp: i32, -}; - -fn slab(str: []const u8, exp: i32) Slab { - return Slab{ - .str = str, - .exp = exp, - }; -} - -pub const enum3_data = [_]Slab{ - slab("40648030339495312", 69), - slab("4498645355592131", -134), - slab("678321594594593", 244), - slab("36539702510912277", -230), - slab("56819570380646536", -70), - slab("42452693975546964", 175), - slab("34248868699178663", 291), - slab("34037810581283983", -267), - slab("67135881167178176", -188), - slab("74973710847373845", -108), - slab("60272377639347644", -45), - slab("1316415380484425", 116), - slab("64433314612521525", 218), - slab("31961502891542243", 263), - slab("4407140524515149", 303), - slab("69928982131052126", -291), - slab("5331838923808276", -248), - slab("24766435002945523", -208), - slab("21509066976048781", -149), - slab("2347200170470694", -123), - slab("51404180294474556", -89), - slab("12320586499023201", -56), - slab("38099461575161174", 45), - slab("3318949537676913", 79), - slab("48988560059074597", 136), - slab("7955843973866726", 209), - slab("2630089515909384", 227), - slab("11971601492124911", 258), - slab("35394816534699092", 284), - slab("47497368114750945", 299), - slab("54271187548763685", 305), - slab("2504414972009504", -302), - slab("69316187906522606", -275), - slab("53263359599109627", -252), - slab("24384437085962037", -239), - slab("3677854139813342", -213), - slab("44318030915155535", -195), - slab("28150140033551147", -162), - slab("1157373742186464", -143), - slab("2229658838863212", -132), - slab("67817280930489786", -117), - slab("56966478488538934", -92), - slab("49514357246452655", -74), - slab("74426102121433776", -64), - slab("78851753593748485", -55), - slab("19024128529074359", -25), - slab("32118580932839778", 57), - slab("17693166778887419", 72), - slab("78117757194253536", 88), - slab("56627018760181905", 122), - slab("35243988108650928", 153), - slab("38624526316654214", 194), - slab("2397422026462446", 213), - slab("37862966954556723", 224), - slab("56089100059334965", 237), - slab("3666156212014994", 249), - slab("47886405968499643", 258), - slab("48228872759189434", 272), - slab("29980574575739863", 289), - slab("37049827284413546", 297), - slab("37997894491800756", 300), - slab("37263572163337027", 304), - slab("16973149506391291", 308), - slab("391314839376485", -304), - slab("38797447671091856", -300), - slab("54994366114768736", -281), - slab("23593494977819109", -270), - slab("61359116592542813", -265), - slab("1332959730952069", -248), - slab("6096109271490509", -240), - slab("22874741188249992", -231), - slab("33104948806015703", -227), - slab("21670630627577332", -209), - slab("70547825868713855", -201), - slab("54981742371928845", -192), - slab("27843818440071113", -171), - slab("4504022405368184", -161), - slab("2548351460621656", -148), - slab("4629494968745856", -143), - slab("557414709715803", -133), - slab("23897004381644022", -131), - slab("33057350728075958", -117), - slab("47628822744182433", -112), - slab("22520091703825729", -96), - slab("1285104507361864", -89), - slab("46239793787746783", -81), - slab("330095714976351", -73), - slab("4994144928421182", -66), - slab("77003665618895", -58), - slab("49282345996092803", -56), - slab("66534156679273626", -48), - slab("24661175471861008", -36), - slab("45035996273704964", 39), - slab("32402369146794532", 51), - slab("42859354584576066", 61), - slab("1465909318208761", 71), - slab("70772667115549675", 72), - slab("18604316837693468", 86), - slab("38329392744333992", 113), - slab("21062646087750798", 117), - slab("972708181182949", 132), - slab("36683053719290777", 146), - slab("32106017483029628", 166), - slab("41508952543121158", 190), - slab("45072812455233127", 205), - slab("59935550661561155", 212), - slab("40270821632825953", 217), - slab("60846862848160256", 219), - slab("42788225889846894", 225), - slab("28044550029667482", 237), - slab("46475406389115295", 240), - slab("7546114860200514", 246), - slab("7332312424029988", 249), - slab("23943202984249821", 258), - slab("15980751445771122", 263), - slab("21652206566352648", 272), - slab("65171333649148234", 278), - slab("70789633069398184", 284), - slab("68600253110025576", 290), - slab("4234784709771466", 295), - slab("14819930913765419", 298), - slab("9499473622950189", 299), - slab("71272819274635585", 302), - slab("16959746108988652", 304), - slab("13567796887190921", 305), - slab("4735325513114182", 306), - slab("67892598025565165", 308), - slab("81052743999542975", -307), - slab("4971131903427841", -303), - slab("19398723835545928", -300), - slab("29232758945460627", -298), - slab("27497183057384368", -281), - slab("17970091719480621", -275), - slab("22283747288943228", -274), - slab("47186989955638217", -270), - slab("6819439187504402", -266), - slab("47902021250710456", -262), - slab("41378294570975613", -249), - slab("2665919461904138", -248), - slab("3421423777071132", -247), - slab("12192218542981019", -239), - slab("7147520638007367", -235), - slab("45749482376499984", -231), - slab("80596937390013985", -229), - slab("26761990828289327", -214), - slab("18738512510673039", -211), - slab("619160875073638", -209), - slab("403997300048931", -206), - slab("22159015457577768", -195), - slab("13745435592982211", -192), - slab("33567940583589088", -188), - slab("4812711195250522", -184), - slab("3591036630219558", -167), - slab("1126005601342046", -161), - slab("5047135806497922", -154), - slab("43018133952097563", -149), - slab("45209911804158747", -146), - slab("2314747484372928", -143), - slab("65509428048152994", -138), - slab("2787073548579015", -133), - slab("1114829419431606", -132), - slab("4459317677726424", -132), - slab("32269008655522087", -128), - slab("16528675364037979", -117), - slab("66114701456151916", -117), - slab("54934856534126976", -116), - slab("21168365664081082", -111), - slab("67445733463759384", -104), - slab("45590931008842566", -95), - slab("8031903171011649", -91), - slab("2570209014723728", -89), - slab("6516605505584466", -89), - slab("32943123175907307", -78), - slab("82523928744087755", -74), - slab("28409785190323268", -70), - slab("52853886779813977", -69), - slab("30417302377115577", -65), - slab("1925091640472375", -58), - slab("30801466247558002", -57), - slab("24641172998046401", -56), - slab("19712938398437121", -55), - slab("43129529027318865", -52), - slab("15068094409836911", -45), - slab("48658418478920193", -41), - slab("49322350943722016", -36), - slab("38048257058148717", -25), - slab("14411294198511291", 45), - slab("32745697577386472", 48), - slab("16059290466419889", 57), - slab("64237161865679556", 57), - slab("8003248329710242", 63), - slab("81296060678990625", 69), - slab("8846583389443709", 71), - slab("35386333557774838", 72), - slab("21606114462319112", 74), - slab("18413733104063271", 84), - slab("35887030159858487", 87), - slab("2825769263311679", 104), - slab("2138446062528161", 114), - slab("52656615219377", 116), - slab("16850116870200639", 118), - slab("48635409059147446", 132), - slab("12247140014768649", 136), - slab("16836228873919609", 138), - slab("5225574770881846", 147), - slab("42745323906998127", 155), - slab("10613173493886741", 175), - slab("10377238135780289", 190), - slab("29480080280199528", 191), - slab("4679330956996797", 201), - slab("3977921986933363", 209), - slab("56560320317673966", 210), - slab("1198711013231223", 213), - slab("4794844052924892", 213), - slab("16108328653130381", 218), - slab("57878622568856074", 219), - slab("18931483477278361", 224), - slab("4278822588984689", 225), - slab("1315044757954692", 227), - slab("14022275014833741", 237), - slab("5143975308105889", 237), - slab("64517311884236306", 238), - slab("3391607972972965", 244), - slab("3773057430100257", 246), - slab("1833078106007497", 249), - slab("64766168833734675", 249), - slab("1197160149212491", 258), - slab("2394320298424982", 258), - slab("4788640596849964", 258), - slab("1598075144577112", 263), - slab("3196150289154224", 263), - slab("83169412421960475", 271), - slab("43304413132705296", 272), - slab("5546524276967009", 277), - slab("3539481653469909", 284), - slab("7078963306939818", 284), - slab("14990287287869931", 289), - slab("34300126555012788", 290), - slab("17124434349589332", 291), - slab("2117392354885733", 295), - slab("47639264836707725", 296), - slab("7409965456882709", 297), - slab("29639861827530837", 298), - slab("79407577493590275", 299), - slab("18998947245900378", 300), - slab("35636409637317792", 302), - slab("23707742595255608", 303), - slab("47415485190511216", 303), - slab("33919492217977303", 304), - slab("6783898443595461", 304), - slab("27135593774381842", 305), - slab("2367662756557091", 306), - slab("44032152438472327", 307), - slab("33946299012782582", 308), - slab("17976931348623157", 309), - slab("40526371999771488", -307), - slab("1956574196882425", -304), - slab("78262967875297", -304), - slab("1252207486004752", -302), - slab("5008829944019008", -302), - slab("1939872383554593", -300), - slab("3879744767109186", -300), - slab("44144884605471774", -291), - slab("45129663866844427", -289), - slab("2749718305738437", -281), - slab("5499436611476874", -281), - slab("35940183438961242", -275), - slab("71880366877922484", -275), - slab("44567494577886457", -274), - slab("25789638850173173", -270), - slab("17018905290641991", -267), - slab("3409719593752201", -266), - slab("6135911659254281", -265), - slab("23951010625355228", -262), - slab("51061856989121905", -260), - slab("4137829457097561", -249), - slab("13329597309520689", -248), - slab("26659194619041378", -248), - slab("53318389238082755", -248), - slab("1710711888535566", -247), - slab("6842847554142264", -247), - slab("609610927149051", -240), - slab("1219221854298102", -239), - slab("2438443708596204", -239), - slab("2287474118824999", -231), - slab("4574948237649998", -231), - slab("18269851255456139", -230), - slab("40298468695006992", -229), - slab("16552474403007851", -227), - slab("39050270537318193", -217), - slab("1838927069906671", -213), - slab("7355708279626684", -213), - slab("37477025021346077", -211), - slab("43341261255154663", -209), - slab("12383217501472761", -208), - slab("2019986500244655", -206), - slab("35273912934356928", -201), - slab("47323883490786093", -199), - slab("2215901545757777", -195), - slab("4431803091515554", -195), - slab("27490871185964422", -192), - slab("64710073234908765", -189), - slab("57511323531737074", -188), - slab("2406355597625261", -184), - slab("75862936714499446", -176), - slab("1795518315109779", -167), - slab("7182073260439116", -167), - slab("563002800671023", -162), - slab("2252011202684092", -161), - slab("2523567903248961", -154), - slab("10754533488024391", -149), - slab("37436263604934127", -149), - slab("1274175730310828", -148), - slab("5096702921243312", -148), - slab("11573737421864639", -143), - slab("23147474843729279", -143), - slab("46294949687458557", -143), - slab("36067106647774144", -141), - slab("44986453555921307", -134), - slab("27870735485790148", -133), - slab("55741470971580295", -133), - slab("11148294194316059", -132), - slab("22296588388632118", -132), - slab("44593176777264236", -132), - slab("11948502190822011", -131), - slab("47794008763288043", -131), - slab("1173600085235347", -123), - slab("4694400340941388", -123), - slab("1652867536403798", -117), - slab("3305735072807596", -117), - slab("6611470145615192", -117), - slab("27467428267063488", -116), - slab("4762882274418243", -112), - slab("10584182832040541", -111), - slab("42336731328162165", -111), - slab("33722866731879692", -104), - slab("69097540994131414", -98), - slab("45040183407651457", -96), - slab("5696647848853893", -92), - slab("40159515855058247", -91), - slab("12851045073618639", -89), - slab("25702090147237278", -89), - slab("3258302752792233", -89), - slab("5140418029447456", -89), - slab("23119896893873391", -81), - slab("51753157237874753", -81), - slab("67761208324172855", -77), - slab("8252392874408775", -74), - slab("1650478574881755", -73), - slab("660191429952702", -73), - slab("3832399419240467", -70), - slab("26426943389906988", -69), - slab("2497072464210591", -66), - slab("15208651188557789", -65), - slab("37213051060716888", -64), - slab("55574205388093594", -61), - slab("385018328094475", -58), - slab("15400733123779001", -57), - slab("61602932495116004", -57), - slab("14784703798827841", -56), - slab("29569407597655683", -56), - slab("9856469199218561", -56), - slab("39425876796874242", -55), - slab("21564764513659432", -52), - slab("35649516398744314", -48), - slab("51091836539008967", -47), - slab("30136188819673822", -45), - slab("4865841847892019", -41), - slab("33729482964455627", -38), - slab("2466117547186101", -36), - slab("4932235094372202", -36), - slab("1902412852907436", -25), - slab("3804825705814872", -25), - slab("80341375308088225", 44), - slab("28822588397022582", 45), - slab("57645176794045164", 45), - slab("65491395154772944", 48), - slab("64804738293589064", 51), - slab("1605929046641989", 57), - slab("3211858093283978", 57), - slab("6423716186567956", 57), - slab("4001624164855121", 63), - slab("4064803033949531", 69), - slab("8129606067899062", 69), - slab("4384946084578497", 70), - slab("2931818636417522", 71), - slab("884658338944371", 71), - slab("1769316677888742", 72), - slab("3538633355777484", 72), - slab("7077266711554968", 72), - slab("43212228924638223", 74), - slab("6637899075353826", 79), - slab("36827466208126543", 84), - slab("37208633675386937", 86), - slab("39058878597126768", 88), - slab("57654578150150385", 91), - slab("5651538526623358", 104), - slab("76658785488667984", 113), - slab("4276892125056322", 114), - slab("263283076096885", 116), - slab("10531323043875399", 117), - slab("42125292175501597", 117), - slab("33700233740401277", 118), - slab("44596066840334405", 125), - slab("9727081811829489", 132), - slab("61235700073843246", 135), - slab("24494280029537298", 136), - slab("4499029632233837", 137), - slab("18341526859645389", 146), - slab("2612787385440923", 147), - slab("6834859331393543", 147), - slab("70487976217301855", 153), - slab("40366692112133834", 160), - slab("64212034966059256", 166), - slab("21226346987773482", 175), - slab("51886190678901447", 189), - slab("20754476271560579", 190), - slab("83017905086242315", 190), - slab("58960160560399056", 191), - slab("66641177824100826", 194), - slab("5493127645170153", 201), - slab("39779219869333628", 209), - slab("79558439738667255", 209), - slab("50523702331566894", 210), - slab("40933393326155808", 212), - slab("81866786652311615", 212), - slab("11987110132312231", 213), - slab("23974220264624462", 213), - slab("47948440529248924", 213), - slab("8054164326565191", 217), - slab("32216657306260762", 218), - slab("30423431424080128", 219), -}; diff --git a/lib/std/fmt/errol/lookup.zig b/lib/std/fmt/errol/lookup.zig deleted file mode 100644 index 2fb6b167bb49..000000000000 --- a/lib/std/fmt/errol/lookup.zig +++ /dev/null @@ -1,606 +0,0 @@ -pub const HP = struct { - val: f64, - off: f64, -}; -pub const lookup_table = [_]HP{ - HP{ .val = 1.000000e+308, .off = -1.097906362944045488e+291 }, - HP{ .val = 1.000000e+307, .off = 1.396894023974354241e+290 }, - HP{ .val = 1.000000e+306, .off = -1.721606459673645508e+289 }, - HP{ .val = 1.000000e+305, .off = 6.074644749446353973e+288 }, - HP{ .val = 1.000000e+304, .off = 6.074644749446353567e+287 }, - HP{ .val = 1.000000e+303, .off = -1.617650767864564452e+284 }, - HP{ .val = 1.000000e+302, .off = -7.629703079084895055e+285 }, - HP{ .val = 1.000000e+301, .off = -5.250476025520442286e+284 }, - HP{ .val = 1.000000e+300, .off = -5.250476025520441956e+283 }, - HP{ .val = 1.000000e+299, .off = -5.250476025520441750e+282 }, - HP{ .val = 1.000000e+298, .off = 4.043379652465702264e+281 }, - HP{ .val = 1.000000e+297, .off = -1.765280146275637946e+280 }, - HP{ .val = 1.000000e+296, .off = 1.865132227937699609e+279 }, - HP{ .val = 1.000000e+295, .off = 1.865132227937699609e+278 }, - HP{ .val = 1.000000e+294, .off = -6.643646774124810287e+277 }, - HP{ .val = 1.000000e+293, .off = 7.537651562646039934e+276 }, - HP{ .val = 1.000000e+292, .off = -1.325659897835741608e+275 }, - HP{ .val = 1.000000e+291, .off = 4.213909764965371606e+274 }, - HP{ .val = 1.000000e+290, .off = -6.172783352786715670e+273 }, - HP{ .val = 1.000000e+289, .off = -6.172783352786715670e+272 }, - HP{ .val = 1.000000e+288, .off = -7.630473539575035471e+270 }, - HP{ .val = 1.000000e+287, .off = -7.525217352494018700e+270 }, - HP{ .val = 1.000000e+286, .off = -3.298861103408696612e+269 }, - HP{ .val = 1.000000e+285, .off = 1.984084207947955778e+268 }, - HP{ .val = 1.000000e+284, .off = -7.921438250845767591e+267 }, - HP{ .val = 1.000000e+283, .off = 4.460464822646386735e+266 }, - HP{ .val = 1.000000e+282, .off = -3.278224598286209647e+265 }, - HP{ .val = 1.000000e+281, .off = -3.278224598286209737e+264 }, - HP{ .val = 1.000000e+280, .off = -3.278224598286209961e+263 }, - HP{ .val = 1.000000e+279, .off = -5.797329227496039232e+262 }, - HP{ .val = 1.000000e+278, .off = 3.649313132040821498e+261 }, - HP{ .val = 1.000000e+277, .off = -2.867878510995372374e+259 }, - HP{ .val = 1.000000e+276, .off = -5.206914080024985409e+259 }, - HP{ .val = 1.000000e+275, .off = 4.018322599210230404e+258 }, - HP{ .val = 1.000000e+274, .off = 7.862171215558236495e+257 }, - HP{ .val = 1.000000e+273, .off = 5.459765830340732821e+256 }, - HP{ .val = 1.000000e+272, .off = -6.552261095746788047e+255 }, - HP{ .val = 1.000000e+271, .off = 4.709014147460262298e+254 }, - HP{ .val = 1.000000e+270, .off = -4.675381888545612729e+253 }, - HP{ .val = 1.000000e+269, .off = -4.675381888545612892e+252 }, - HP{ .val = 1.000000e+268, .off = 2.656177514583977380e+251 }, - HP{ .val = 1.000000e+267, .off = 2.656177514583977190e+250 }, - HP{ .val = 1.000000e+266, .off = -3.071603269111014892e+249 }, - HP{ .val = 1.000000e+265, .off = -6.651466258920385440e+248 }, - HP{ .val = 1.000000e+264, .off = -4.414051890289528972e+247 }, - HP{ .val = 1.000000e+263, .off = -1.617283929500958387e+246 }, - HP{ .val = 1.000000e+262, .off = -1.617283929500958241e+245 }, - HP{ .val = 1.000000e+261, .off = 7.122615947963323868e+244 }, - HP{ .val = 1.000000e+260, .off = -6.533477610574617382e+243 }, - HP{ .val = 1.000000e+259, .off = 7.122615947963323982e+242 }, - HP{ .val = 1.000000e+258, .off = -5.679971763165996225e+241 }, - HP{ .val = 1.000000e+257, .off = -3.012765990014054219e+240 }, - HP{ .val = 1.000000e+256, .off = -3.012765990014054219e+239 }, - HP{ .val = 1.000000e+255, .off = 1.154743030535854616e+238 }, - HP{ .val = 1.000000e+254, .off = 6.364129306223240767e+237 }, - HP{ .val = 1.000000e+253, .off = 6.364129306223241129e+236 }, - HP{ .val = 1.000000e+252, .off = -9.915202805299840595e+235 }, - HP{ .val = 1.000000e+251, .off = -4.827911520448877980e+234 }, - HP{ .val = 1.000000e+250, .off = 7.890316691678530146e+233 }, - HP{ .val = 1.000000e+249, .off = 7.890316691678529484e+232 }, - HP{ .val = 1.000000e+248, .off = -4.529828046727141859e+231 }, - HP{ .val = 1.000000e+247, .off = 4.785280507077111924e+230 }, - HP{ .val = 1.000000e+246, .off = -6.858605185178205305e+229 }, - HP{ .val = 1.000000e+245, .off = -4.432795665958347728e+228 }, - HP{ .val = 1.000000e+244, .off = -7.465057564983169531e+227 }, - HP{ .val = 1.000000e+243, .off = -7.465057564983169741e+226 }, - HP{ .val = 1.000000e+242, .off = -5.096102956370027445e+225 }, - HP{ .val = 1.000000e+241, .off = -5.096102956370026952e+224 }, - HP{ .val = 1.000000e+240, .off = -1.394611380411992474e+223 }, - HP{ .val = 1.000000e+239, .off = 9.188208545617793960e+221 }, - HP{ .val = 1.000000e+238, .off = -4.864759732872650359e+221 }, - HP{ .val = 1.000000e+237, .off = 5.979453868566904629e+220 }, - HP{ .val = 1.000000e+236, .off = -5.316601966265964857e+219 }, - HP{ .val = 1.000000e+235, .off = -5.316601966265964701e+218 }, - HP{ .val = 1.000000e+234, .off = -1.786584517880693123e+217 }, - HP{ .val = 1.000000e+233, .off = 2.625937292600896716e+216 }, - HP{ .val = 1.000000e+232, .off = -5.647541102052084079e+215 }, - HP{ .val = 1.000000e+231, .off = -5.647541102052083888e+214 }, - HP{ .val = 1.000000e+230, .off = -9.956644432600511943e+213 }, - HP{ .val = 1.000000e+229, .off = 8.161138937705571862e+211 }, - HP{ .val = 1.000000e+228, .off = 7.549087847752475275e+211 }, - HP{ .val = 1.000000e+227, .off = -9.283347037202319948e+210 }, - HP{ .val = 1.000000e+226, .off = 3.866992716668613820e+209 }, - HP{ .val = 1.000000e+225, .off = 7.154577655136347262e+208 }, - HP{ .val = 1.000000e+224, .off = 3.045096482051680688e+207 }, - HP{ .val = 1.000000e+223, .off = -4.660180717482069567e+206 }, - HP{ .val = 1.000000e+222, .off = -4.660180717482070101e+205 }, - HP{ .val = 1.000000e+221, .off = -4.660180717482069544e+204 }, - HP{ .val = 1.000000e+220, .off = 3.562757926310489022e+202 }, - HP{ .val = 1.000000e+219, .off = 3.491561111451748149e+202 }, - HP{ .val = 1.000000e+218, .off = -8.265758834125874135e+201 }, - HP{ .val = 1.000000e+217, .off = 3.981449442517482365e+200 }, - HP{ .val = 1.000000e+216, .off = -2.142154695804195936e+199 }, - HP{ .val = 1.000000e+215, .off = 9.339603063548950188e+198 }, - HP{ .val = 1.000000e+214, .off = 4.555537330485139746e+197 }, - HP{ .val = 1.000000e+213, .off = 1.565496247320257804e+196 }, - HP{ .val = 1.000000e+212, .off = 9.040598955232462036e+195 }, - HP{ .val = 1.000000e+211, .off = 4.368659762787334780e+194 }, - HP{ .val = 1.000000e+210, .off = 7.288621758065539072e+193 }, - HP{ .val = 1.000000e+209, .off = -7.311188218325485628e+192 }, - HP{ .val = 1.000000e+208, .off = 1.813693016918905189e+191 }, - HP{ .val = 1.000000e+207, .off = -3.889357755108838992e+190 }, - HP{ .val = 1.000000e+206, .off = -3.889357755108838992e+189 }, - HP{ .val = 1.000000e+205, .off = -1.661603547285501360e+188 }, - HP{ .val = 1.000000e+204, .off = 1.123089212493670643e+187 }, - HP{ .val = 1.000000e+203, .off = 1.123089212493670643e+186 }, - HP{ .val = 1.000000e+202, .off = 9.825254086803583029e+185 }, - HP{ .val = 1.000000e+201, .off = -3.771878529305654999e+184 }, - HP{ .val = 1.000000e+200, .off = 3.026687778748963675e+183 }, - HP{ .val = 1.000000e+199, .off = -9.720624048853446693e+182 }, - HP{ .val = 1.000000e+198, .off = -1.753554156601940139e+181 }, - HP{ .val = 1.000000e+197, .off = 4.885670753607648963e+180 }, - HP{ .val = 1.000000e+196, .off = 4.885670753607648963e+179 }, - HP{ .val = 1.000000e+195, .off = 2.292223523057028076e+178 }, - HP{ .val = 1.000000e+194, .off = 5.534032561245303825e+177 }, - HP{ .val = 1.000000e+193, .off = -6.622751331960730683e+176 }, - HP{ .val = 1.000000e+192, .off = -4.090088020876139692e+175 }, - HP{ .val = 1.000000e+191, .off = -7.255917159731877552e+174 }, - HP{ .val = 1.000000e+190, .off = -7.255917159731877992e+173 }, - HP{ .val = 1.000000e+189, .off = -2.309309130269787104e+172 }, - HP{ .val = 1.000000e+188, .off = -2.309309130269787019e+171 }, - HP{ .val = 1.000000e+187, .off = 9.284303438781988230e+170 }, - HP{ .val = 1.000000e+186, .off = 2.038295583124628364e+169 }, - HP{ .val = 1.000000e+185, .off = 2.038295583124628532e+168 }, - HP{ .val = 1.000000e+184, .off = -1.735666841696912925e+167 }, - HP{ .val = 1.000000e+183, .off = 5.340512704843477241e+166 }, - HP{ .val = 1.000000e+182, .off = -6.453119872723839321e+165 }, - HP{ .val = 1.000000e+181, .off = 8.288920849235306587e+164 }, - HP{ .val = 1.000000e+180, .off = -9.248546019891598293e+162 }, - HP{ .val = 1.000000e+179, .off = 1.954450226518486016e+162 }, - HP{ .val = 1.000000e+178, .off = -5.243811844750628197e+161 }, - HP{ .val = 1.000000e+177, .off = -7.448980502074320639e+159 }, - HP{ .val = 1.000000e+176, .off = -7.448980502074319858e+158 }, - HP{ .val = 1.000000e+175, .off = 6.284654753766312753e+158 }, - HP{ .val = 1.000000e+174, .off = -6.895756753684458388e+157 }, - HP{ .val = 1.000000e+173, .off = -1.403918625579970616e+156 }, - HP{ .val = 1.000000e+172, .off = -8.268716285710580522e+155 }, - HP{ .val = 1.000000e+171, .off = 4.602779327034313170e+154 }, - HP{ .val = 1.000000e+170, .off = -3.441905430931244940e+153 }, - HP{ .val = 1.000000e+169, .off = 6.613950516525702884e+152 }, - HP{ .val = 1.000000e+168, .off = 6.613950516525702652e+151 }, - HP{ .val = 1.000000e+167, .off = -3.860899428741951187e+150 }, - HP{ .val = 1.000000e+166, .off = 5.959272394946474605e+149 }, - HP{ .val = 1.000000e+165, .off = 1.005101065481665103e+149 }, - HP{ .val = 1.000000e+164, .off = -1.783349948587918355e+146 }, - HP{ .val = 1.000000e+163, .off = 6.215006036188360099e+146 }, - HP{ .val = 1.000000e+162, .off = 6.215006036188360099e+145 }, - HP{ .val = 1.000000e+161, .off = -3.774589324822814903e+144 }, - HP{ .val = 1.000000e+160, .off = -6.528407745068226929e+142 }, - HP{ .val = 1.000000e+159, .off = 7.151530601283157561e+142 }, - HP{ .val = 1.000000e+158, .off = 4.712664546348788765e+141 }, - HP{ .val = 1.000000e+157, .off = 1.664081977680827856e+140 }, - HP{ .val = 1.000000e+156, .off = 1.664081977680827750e+139 }, - HP{ .val = 1.000000e+155, .off = -7.176231540910168265e+137 }, - HP{ .val = 1.000000e+154, .off = -3.694754568805822650e+137 }, - HP{ .val = 1.000000e+153, .off = 2.665969958768462622e+134 }, - HP{ .val = 1.000000e+152, .off = -4.625108135904199522e+135 }, - HP{ .val = 1.000000e+151, .off = -1.717753238721771919e+134 }, - HP{ .val = 1.000000e+150, .off = 1.916440382756262433e+133 }, - HP{ .val = 1.000000e+149, .off = -4.897672657515052040e+132 }, - HP{ .val = 1.000000e+148, .off = -4.897672657515052198e+131 }, - HP{ .val = 1.000000e+147, .off = 2.200361759434233991e+130 }, - HP{ .val = 1.000000e+146, .off = 6.636633270027537273e+129 }, - HP{ .val = 1.000000e+145, .off = 1.091293881785907977e+128 }, - HP{ .val = 1.000000e+144, .off = -2.374543235865110597e+127 }, - HP{ .val = 1.000000e+143, .off = -2.374543235865110537e+126 }, - HP{ .val = 1.000000e+142, .off = -5.082228484029969099e+125 }, - HP{ .val = 1.000000e+141, .off = -1.697621923823895943e+124 }, - HP{ .val = 1.000000e+140, .off = -5.928380124081487212e+123 }, - HP{ .val = 1.000000e+139, .off = -3.284156248920492522e+122 }, - HP{ .val = 1.000000e+138, .off = -3.284156248920492706e+121 }, - HP{ .val = 1.000000e+137, .off = -3.284156248920492476e+120 }, - HP{ .val = 1.000000e+136, .off = -5.866406127007401066e+119 }, - HP{ .val = 1.000000e+135, .off = 3.817030915818506056e+118 }, - HP{ .val = 1.000000e+134, .off = 7.851796350329300951e+117 }, - HP{ .val = 1.000000e+133, .off = -2.235117235947686077e+116 }, - HP{ .val = 1.000000e+132, .off = 9.170432597638723691e+114 }, - HP{ .val = 1.000000e+131, .off = 8.797444499042767883e+114 }, - HP{ .val = 1.000000e+130, .off = -5.978307824605161274e+113 }, - HP{ .val = 1.000000e+129, .off = 1.782556435814758516e+111 }, - HP{ .val = 1.000000e+128, .off = -7.517448691651820362e+111 }, - HP{ .val = 1.000000e+127, .off = 4.507089332150205498e+110 }, - HP{ .val = 1.000000e+126, .off = 7.513223838100711695e+109 }, - HP{ .val = 1.000000e+125, .off = 7.513223838100712113e+108 }, - HP{ .val = 1.000000e+124, .off = 5.164681255326878494e+107 }, - HP{ .val = 1.000000e+123, .off = 2.229003026859587122e+106 }, - HP{ .val = 1.000000e+122, .off = -1.440594758724527399e+105 }, - HP{ .val = 1.000000e+121, .off = -3.734093374714598783e+104 }, - HP{ .val = 1.000000e+120, .off = 1.999653165260579757e+103 }, - HP{ .val = 1.000000e+119, .off = 5.583244752745066693e+102 }, - HP{ .val = 1.000000e+118, .off = 3.343500010567262234e+101 }, - HP{ .val = 1.000000e+117, .off = -5.055542772599503556e+100 }, - HP{ .val = 1.000000e+116, .off = -1.555941612946684331e+99 }, - HP{ .val = 1.000000e+115, .off = -1.555941612946684331e+98 }, - HP{ .val = 1.000000e+114, .off = -1.555941612946684293e+97 }, - HP{ .val = 1.000000e+113, .off = -1.555941612946684246e+96 }, - HP{ .val = 1.000000e+112, .off = 6.988006530736955847e+95 }, - HP{ .val = 1.000000e+111, .off = 4.318022735835818244e+94 }, - HP{ .val = 1.000000e+110, .off = -2.356936751417025578e+93 }, - HP{ .val = 1.000000e+109, .off = 1.814912928116001926e+92 }, - HP{ .val = 1.000000e+108, .off = -3.399899171300282744e+91 }, - HP{ .val = 1.000000e+107, .off = 3.118615952970072913e+90 }, - HP{ .val = 1.000000e+106, .off = -9.103599905036843605e+89 }, - HP{ .val = 1.000000e+105, .off = 6.174169917471802325e+88 }, - HP{ .val = 1.000000e+104, .off = -1.915675085734668657e+86 }, - HP{ .val = 1.000000e+103, .off = -1.915675085734668864e+85 }, - HP{ .val = 1.000000e+102, .off = 2.295048673475466221e+85 }, - HP{ .val = 1.000000e+101, .off = 2.295048673475466135e+84 }, - HP{ .val = 1.000000e+100, .off = -1.590289110975991792e+83 }, - HP{ .val = 1.000000e+99, .off = 3.266383119588331155e+82 }, - HP{ .val = 1.000000e+98, .off = 2.309629754856292029e+80 }, - HP{ .val = 1.000000e+97, .off = -7.357587384771124533e+80 }, - HP{ .val = 1.000000e+96, .off = -4.986165397190889509e+79 }, - HP{ .val = 1.000000e+95, .off = -2.021887912715594741e+78 }, - HP{ .val = 1.000000e+94, .off = -2.021887912715594638e+77 }, - HP{ .val = 1.000000e+93, .off = -4.337729697461918675e+76 }, - HP{ .val = 1.000000e+92, .off = -4.337729697461918997e+75 }, - HP{ .val = 1.000000e+91, .off = -7.956232486128049702e+74 }, - HP{ .val = 1.000000e+90, .off = 3.351588728453609882e+73 }, - HP{ .val = 1.000000e+89, .off = 5.246334248081951113e+71 }, - HP{ .val = 1.000000e+88, .off = 4.058327554364963672e+71 }, - HP{ .val = 1.000000e+87, .off = 4.058327554364963918e+70 }, - HP{ .val = 1.000000e+86, .off = -1.463069523067487266e+69 }, - HP{ .val = 1.000000e+85, .off = -1.463069523067487314e+68 }, - HP{ .val = 1.000000e+84, .off = -5.776660989811589441e+67 }, - HP{ .val = 1.000000e+83, .off = -3.080666323096525761e+66 }, - HP{ .val = 1.000000e+82, .off = 3.659320343691134468e+65 }, - HP{ .val = 1.000000e+81, .off = 7.871812010433421235e+64 }, - HP{ .val = 1.000000e+80, .off = -2.660986470836727449e+61 }, - HP{ .val = 1.000000e+79, .off = 3.264399249934044627e+62 }, - HP{ .val = 1.000000e+78, .off = -8.493621433689703070e+60 }, - HP{ .val = 1.000000e+77, .off = 1.721738727445414063e+60 }, - HP{ .val = 1.000000e+76, .off = -4.706013449590547218e+59 }, - HP{ .val = 1.000000e+75, .off = 7.346021882351880518e+58 }, - HP{ .val = 1.000000e+74, .off = 4.835181188197207515e+57 }, - HP{ .val = 1.000000e+73, .off = 1.696630320503867482e+56 }, - HP{ .val = 1.000000e+72, .off = 5.619818905120542959e+55 }, - HP{ .val = 1.000000e+71, .off = -4.188152556421145598e+54 }, - HP{ .val = 1.000000e+70, .off = -7.253143638152923145e+53 }, - HP{ .val = 1.000000e+69, .off = -7.253143638152923145e+52 }, - HP{ .val = 1.000000e+68, .off = 4.719477774861832896e+51 }, - HP{ .val = 1.000000e+67, .off = 1.726322421608144052e+50 }, - HP{ .val = 1.000000e+66, .off = 5.467766613175255107e+49 }, - HP{ .val = 1.000000e+65, .off = 7.909613737163661911e+47 }, - HP{ .val = 1.000000e+64, .off = -2.132041900945439564e+47 }, - HP{ .val = 1.000000e+63, .off = -5.785795994272697265e+46 }, - HP{ .val = 1.000000e+62, .off = -3.502199685943161329e+45 }, - HP{ .val = 1.000000e+61, .off = 5.061286470292598274e+44 }, - HP{ .val = 1.000000e+60, .off = 5.061286470292598472e+43 }, - HP{ .val = 1.000000e+59, .off = 2.831211950439536034e+42 }, - HP{ .val = 1.000000e+58, .off = 5.618805100255863927e+41 }, - HP{ .val = 1.000000e+57, .off = -4.834669211555366251e+40 }, - HP{ .val = 1.000000e+56, .off = -9.190283508143378583e+39 }, - HP{ .val = 1.000000e+55, .off = -1.023506702040855158e+38 }, - HP{ .val = 1.000000e+54, .off = -7.829154040459624616e+37 }, - HP{ .val = 1.000000e+53, .off = 6.779051325638372659e+35 }, - HP{ .val = 1.000000e+52, .off = 6.779051325638372290e+34 }, - HP{ .val = 1.000000e+51, .off = 6.779051325638371598e+33 }, - HP{ .val = 1.000000e+50, .off = -7.629769841091887392e+33 }, - HP{ .val = 1.000000e+49, .off = 5.350972305245182400e+32 }, - HP{ .val = 1.000000e+48, .off = -4.384584304507619764e+31 }, - HP{ .val = 1.000000e+47, .off = -4.384584304507619876e+30 }, - HP{ .val = 1.000000e+46, .off = 6.860180964052978705e+28 }, - HP{ .val = 1.000000e+45, .off = 7.024271097546444878e+28 }, - HP{ .val = 1.000000e+44, .off = -8.821361405306422641e+27 }, - HP{ .val = 1.000000e+43, .off = -1.393721169594140991e+26 }, - HP{ .val = 1.000000e+42, .off = -4.488571267807591679e+25 }, - HP{ .val = 1.000000e+41, .off = -6.200086450407783195e+23 }, - HP{ .val = 1.000000e+40, .off = -3.037860284270036669e+23 }, - HP{ .val = 1.000000e+39, .off = 6.029083362839682141e+22 }, - HP{ .val = 1.000000e+38, .off = 2.251190176543965970e+21 }, - HP{ .val = 1.000000e+37, .off = 4.612373417978788577e+20 }, - HP{ .val = 1.000000e+36, .off = -4.242063737401796198e+19 }, - HP{ .val = 1.000000e+35, .off = 3.136633892082024448e+18 }, - HP{ .val = 1.000000e+34, .off = 5.442476901295718400e+17 }, - HP{ .val = 1.000000e+33, .off = 5.442476901295718400e+16 }, - HP{ .val = 1.000000e+32, .off = -5.366162204393472000e+15 }, - HP{ .val = 1.000000e+31, .off = 3.641037050347520000e+14 }, - HP{ .val = 1.000000e+30, .off = -1.988462483865600000e+13 }, - HP{ .val = 1.000000e+29, .off = 8.566849142784000000e+12 }, - HP{ .val = 1.000000e+28, .off = 4.168802631680000000e+11 }, - HP{ .val = 1.000000e+27, .off = -1.328755507200000000e+10 }, - HP{ .val = 1.000000e+26, .off = -4.764729344000000000e+09 }, - HP{ .val = 1.000000e+25, .off = -9.059696640000000000e+08 }, - HP{ .val = 1.000000e+24, .off = 1.677721600000000000e+07 }, - HP{ .val = 1.000000e+23, .off = 8.388608000000000000e+06 }, - HP{ .val = 1.000000e+22, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+21, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+20, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+19, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+18, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+17, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+16, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+15, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+14, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+13, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+12, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+11, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+10, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+09, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+08, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+07, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+06, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+05, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+04, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+03, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+02, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+01, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e+00, .off = 0.000000000000000000e+00 }, - HP{ .val = 1.000000e-01, .off = -5.551115123125783010e-18 }, - HP{ .val = 1.000000e-02, .off = -2.081668171172168436e-19 }, - HP{ .val = 1.000000e-03, .off = -2.081668171172168557e-20 }, - HP{ .val = 1.000000e-04, .off = -4.792173602385929943e-21 }, - HP{ .val = 1.000000e-05, .off = -8.180305391403130547e-22 }, - HP{ .val = 1.000000e-06, .off = 4.525188817411374069e-23 }, - HP{ .val = 1.000000e-07, .off = 4.525188817411373922e-24 }, - HP{ .val = 1.000000e-08, .off = -2.092256083012847109e-25 }, - HP{ .val = 1.000000e-09, .off = -6.228159145777985254e-26 }, - HP{ .val = 1.000000e-10, .off = -3.643219731549774344e-27 }, - HP{ .val = 1.000000e-11, .off = 6.050303071806019080e-28 }, - HP{ .val = 1.000000e-12, .off = 2.011335237074438524e-29 }, - HP{ .val = 1.000000e-13, .off = -3.037374556340037101e-30 }, - HP{ .val = 1.000000e-14, .off = 1.180690645440101289e-32 }, - HP{ .val = 1.000000e-15, .off = -7.770539987666107583e-32 }, - HP{ .val = 1.000000e-16, .off = 2.090221327596539779e-33 }, - HP{ .val = 1.000000e-17, .off = -7.154242405462192144e-34 }, - HP{ .val = 1.000000e-18, .off = -7.154242405462192572e-35 }, - HP{ .val = 1.000000e-19, .off = 2.475407316473986894e-36 }, - HP{ .val = 1.000000e-20, .off = 5.484672854579042914e-37 }, - HP{ .val = 1.000000e-21, .off = 9.246254777210362522e-38 }, - HP{ .val = 1.000000e-22, .off = -4.859677432657087182e-39 }, - HP{ .val = 1.000000e-23, .off = 3.956530198510069291e-40 }, - HP{ .val = 1.000000e-24, .off = 7.629950044829717753e-41 }, - HP{ .val = 1.000000e-25, .off = -3.849486974919183692e-42 }, - HP{ .val = 1.000000e-26, .off = -3.849486974919184170e-43 }, - HP{ .val = 1.000000e-27, .off = -3.849486974919184070e-44 }, - HP{ .val = 1.000000e-28, .off = 2.876745653839937870e-45 }, - HP{ .val = 1.000000e-29, .off = 5.679342582489572168e-46 }, - HP{ .val = 1.000000e-30, .off = -8.333642060758598930e-47 }, - HP{ .val = 1.000000e-31, .off = -8.333642060758597958e-48 }, - HP{ .val = 1.000000e-32, .off = -5.596730997624190224e-49 }, - HP{ .val = 1.000000e-33, .off = -5.596730997624190604e-50 }, - HP{ .val = 1.000000e-34, .off = 7.232539610818348498e-51 }, - HP{ .val = 1.000000e-35, .off = -7.857545194582380514e-53 }, - HP{ .val = 1.000000e-36, .off = 5.896157255772251528e-53 }, - HP{ .val = 1.000000e-37, .off = -6.632427322784915796e-54 }, - HP{ .val = 1.000000e-38, .off = 3.808059826012723592e-55 }, - HP{ .val = 1.000000e-39, .off = 7.070712060011985131e-56 }, - HP{ .val = 1.000000e-40, .off = 7.070712060011985584e-57 }, - HP{ .val = 1.000000e-41, .off = -5.761291134237854167e-59 }, - HP{ .val = 1.000000e-42, .off = -3.762312935688689794e-59 }, - HP{ .val = 1.000000e-43, .off = -7.745042713519821150e-60 }, - HP{ .val = 1.000000e-44, .off = 4.700987842202462817e-61 }, - HP{ .val = 1.000000e-45, .off = 1.589480203271891964e-62 }, - HP{ .val = 1.000000e-46, .off = -2.299904345391321765e-63 }, - HP{ .val = 1.000000e-47, .off = 2.561826340437695261e-64 }, - HP{ .val = 1.000000e-48, .off = 2.561826340437695345e-65 }, - HP{ .val = 1.000000e-49, .off = 6.360053438741614633e-66 }, - HP{ .val = 1.000000e-50, .off = -7.616223705782342295e-68 }, - HP{ .val = 1.000000e-51, .off = -7.616223705782343324e-69 }, - HP{ .val = 1.000000e-52, .off = -7.616223705782342295e-70 }, - HP{ .val = 1.000000e-53, .off = -3.079876214757872338e-70 }, - HP{ .val = 1.000000e-54, .off = -3.079876214757872821e-71 }, - HP{ .val = 1.000000e-55, .off = 5.423954167728123147e-73 }, - HP{ .val = 1.000000e-56, .off = -3.985444122640543680e-73 }, - HP{ .val = 1.000000e-57, .off = 4.504255013759498850e-74 }, - HP{ .val = 1.000000e-58, .off = -2.570494266573869991e-75 }, - HP{ .val = 1.000000e-59, .off = -2.570494266573869930e-76 }, - HP{ .val = 1.000000e-60, .off = 2.956653608686574324e-77 }, - HP{ .val = 1.000000e-61, .off = -3.952281235388981376e-78 }, - HP{ .val = 1.000000e-62, .off = -3.952281235388981376e-79 }, - HP{ .val = 1.000000e-63, .off = -6.651083908855995172e-80 }, - HP{ .val = 1.000000e-64, .off = 3.469426116645307030e-81 }, - HP{ .val = 1.000000e-65, .off = 7.686305293937516319e-82 }, - HP{ .val = 1.000000e-66, .off = 2.415206322322254927e-83 }, - HP{ .val = 1.000000e-67, .off = 5.709643179581793251e-84 }, - HP{ .val = 1.000000e-68, .off = -6.644495035141475923e-85 }, - HP{ .val = 1.000000e-69, .off = 3.650620143794581913e-86 }, - HP{ .val = 1.000000e-70, .off = 4.333966503770636492e-88 }, - HP{ .val = 1.000000e-71, .off = 8.476455383920859113e-88 }, - HP{ .val = 1.000000e-72, .off = 3.449543675455986564e-89 }, - HP{ .val = 1.000000e-73, .off = 3.077238576654418974e-91 }, - HP{ .val = 1.000000e-74, .off = 4.234998629903623140e-91 }, - HP{ .val = 1.000000e-75, .off = 4.234998629903623412e-92 }, - HP{ .val = 1.000000e-76, .off = 7.303182045714702338e-93 }, - HP{ .val = 1.000000e-77, .off = 7.303182045714701699e-94 }, - HP{ .val = 1.000000e-78, .off = 1.121271649074855759e-96 }, - HP{ .val = 1.000000e-79, .off = 1.121271649074855863e-97 }, - HP{ .val = 1.000000e-80, .off = 3.857468248661243988e-97 }, - HP{ .val = 1.000000e-81, .off = 3.857468248661244248e-98 }, - HP{ .val = 1.000000e-82, .off = 3.857468248661244410e-99 }, - HP{ .val = 1.000000e-83, .off = -3.457651055545315679e-100 }, - HP{ .val = 1.000000e-84, .off = -3.457651055545315933e-101 }, - HP{ .val = 1.000000e-85, .off = 2.257285900866059216e-102 }, - HP{ .val = 1.000000e-86, .off = -8.458220892405268345e-103 }, - HP{ .val = 1.000000e-87, .off = -1.761029146610688867e-104 }, - HP{ .val = 1.000000e-88, .off = 6.610460535632536565e-105 }, - HP{ .val = 1.000000e-89, .off = -3.853901567171494935e-106 }, - HP{ .val = 1.000000e-90, .off = 5.062493089968513723e-108 }, - HP{ .val = 1.000000e-91, .off = -2.218844988608365240e-108 }, - HP{ .val = 1.000000e-92, .off = 1.187522883398155383e-109 }, - HP{ .val = 1.000000e-93, .off = 9.703442563414457296e-110 }, - HP{ .val = 1.000000e-94, .off = 4.380992763404268896e-111 }, - HP{ .val = 1.000000e-95, .off = 1.054461638397900823e-112 }, - HP{ .val = 1.000000e-96, .off = 9.370789450913819736e-113 }, - HP{ .val = 1.000000e-97, .off = -3.623472756142303998e-114 }, - HP{ .val = 1.000000e-98, .off = 6.122223899149788839e-115 }, - HP{ .val = 1.000000e-99, .off = -1.999189980260288281e-116 }, - HP{ .val = 1.000000e-100, .off = -1.999189980260288281e-117 }, - HP{ .val = 1.000000e-101, .off = -5.171617276904849634e-118 }, - HP{ .val = 1.000000e-102, .off = 6.724985085512256320e-119 }, - HP{ .val = 1.000000e-103, .off = 4.246526260008692213e-120 }, - HP{ .val = 1.000000e-104, .off = 7.344599791888147003e-121 }, - HP{ .val = 1.000000e-105, .off = 3.472007877038828407e-122 }, - HP{ .val = 1.000000e-106, .off = 5.892377823819652194e-123 }, - HP{ .val = 1.000000e-107, .off = -1.585470431324073925e-125 }, - HP{ .val = 1.000000e-108, .off = -3.940375084977444795e-125 }, - HP{ .val = 1.000000e-109, .off = 7.869099673288519908e-127 }, - HP{ .val = 1.000000e-110, .off = -5.122196348054018581e-127 }, - HP{ .val = 1.000000e-111, .off = -8.815387795168313713e-128 }, - HP{ .val = 1.000000e-112, .off = 5.034080131510290214e-129 }, - HP{ .val = 1.000000e-113, .off = 2.148774313452247863e-130 }, - HP{ .val = 1.000000e-114, .off = -5.064490231692858416e-131 }, - HP{ .val = 1.000000e-115, .off = -5.064490231692858166e-132 }, - HP{ .val = 1.000000e-116, .off = 5.708726942017560559e-134 }, - HP{ .val = 1.000000e-117, .off = -2.951229134482377772e-134 }, - HP{ .val = 1.000000e-118, .off = 1.451398151372789513e-135 }, - HP{ .val = 1.000000e-119, .off = -1.300243902286690040e-136 }, - HP{ .val = 1.000000e-120, .off = 2.139308664787659449e-137 }, - HP{ .val = 1.000000e-121, .off = 2.139308664787659329e-138 }, - HP{ .val = 1.000000e-122, .off = -5.922142664292847471e-139 }, - HP{ .val = 1.000000e-123, .off = -5.922142664292846912e-140 }, - HP{ .val = 1.000000e-124, .off = 6.673875037395443799e-141 }, - HP{ .val = 1.000000e-125, .off = -1.198636026159737932e-142 }, - HP{ .val = 1.000000e-126, .off = 5.361789860136246995e-143 }, - HP{ .val = 1.000000e-127, .off = -2.838742497733733936e-144 }, - HP{ .val = 1.000000e-128, .off = -5.401408859568103261e-145 }, - HP{ .val = 1.000000e-129, .off = 7.411922949603743011e-146 }, - HP{ .val = 1.000000e-130, .off = -8.604741811861064385e-147 }, - HP{ .val = 1.000000e-131, .off = 1.405673664054439890e-148 }, - HP{ .val = 1.000000e-132, .off = 1.405673664054439933e-149 }, - HP{ .val = 1.000000e-133, .off = -6.414963426504548053e-150 }, - HP{ .val = 1.000000e-134, .off = -3.971014335704864578e-151 }, - HP{ .val = 1.000000e-135, .off = -3.971014335704864748e-152 }, - HP{ .val = 1.000000e-136, .off = -1.523438813303585576e-154 }, - HP{ .val = 1.000000e-137, .off = 2.234325152653707766e-154 }, - HP{ .val = 1.000000e-138, .off = -6.715683724786540160e-155 }, - HP{ .val = 1.000000e-139, .off = -2.986513359186437306e-156 }, - HP{ .val = 1.000000e-140, .off = 1.674949597813692102e-157 }, - HP{ .val = 1.000000e-141, .off = -4.151879098436469092e-158 }, - HP{ .val = 1.000000e-142, .off = -4.151879098436469295e-159 }, - HP{ .val = 1.000000e-143, .off = 4.952540739454407825e-160 }, - HP{ .val = 1.000000e-144, .off = 4.952540739454407667e-161 }, - HP{ .val = 1.000000e-145, .off = 8.508954738630531443e-162 }, - HP{ .val = 1.000000e-146, .off = -2.604839008794855481e-163 }, - HP{ .val = 1.000000e-147, .off = 2.952057864917838382e-164 }, - HP{ .val = 1.000000e-148, .off = 6.425118410988271757e-165 }, - HP{ .val = 1.000000e-149, .off = 2.083792728400229858e-166 }, - HP{ .val = 1.000000e-150, .off = -6.295358232172964237e-168 }, - HP{ .val = 1.000000e-151, .off = 6.153785555826519421e-168 }, - HP{ .val = 1.000000e-152, .off = -6.564942029880634994e-169 }, - HP{ .val = 1.000000e-153, .off = -3.915207116191644540e-170 }, - HP{ .val = 1.000000e-154, .off = 2.709130168030831503e-171 }, - HP{ .val = 1.000000e-155, .off = -1.431080634608215966e-172 }, - HP{ .val = 1.000000e-156, .off = -4.018712386257620994e-173 }, - HP{ .val = 1.000000e-157, .off = 5.684906682427646782e-174 }, - HP{ .val = 1.000000e-158, .off = -6.444617153428937489e-175 }, - HP{ .val = 1.000000e-159, .off = 1.136335243981427681e-176 }, - HP{ .val = 1.000000e-160, .off = 1.136335243981427725e-177 }, - HP{ .val = 1.000000e-161, .off = -2.812077463003137395e-178 }, - HP{ .val = 1.000000e-162, .off = 4.591196362592922204e-179 }, - HP{ .val = 1.000000e-163, .off = 7.675893789924613703e-180 }, - HP{ .val = 1.000000e-164, .off = 3.820022005759999543e-181 }, - HP{ .val = 1.000000e-165, .off = -9.998177244457686588e-183 }, - HP{ .val = 1.000000e-166, .off = -4.012217555824373639e-183 }, - HP{ .val = 1.000000e-167, .off = -2.467177666011174334e-185 }, - HP{ .val = 1.000000e-168, .off = -4.953592503130188139e-185 }, - HP{ .val = 1.000000e-169, .off = -2.011795792799518887e-186 }, - HP{ .val = 1.000000e-170, .off = 1.665450095113817423e-187 }, - HP{ .val = 1.000000e-171, .off = 1.665450095113817487e-188 }, - HP{ .val = 1.000000e-172, .off = -4.080246604750770577e-189 }, - HP{ .val = 1.000000e-173, .off = -4.080246604750770677e-190 }, - HP{ .val = 1.000000e-174, .off = 4.085789420184387951e-192 }, - HP{ .val = 1.000000e-175, .off = 4.085789420184388146e-193 }, - HP{ .val = 1.000000e-176, .off = 4.085789420184388146e-194 }, - HP{ .val = 1.000000e-177, .off = 4.792197640035244894e-194 }, - HP{ .val = 1.000000e-178, .off = 4.792197640035244742e-195 }, - HP{ .val = 1.000000e-179, .off = -2.057206575616014662e-196 }, - HP{ .val = 1.000000e-180, .off = -2.057206575616014662e-197 }, - HP{ .val = 1.000000e-181, .off = -4.732755097354788053e-198 }, - HP{ .val = 1.000000e-182, .off = -4.732755097354787867e-199 }, - HP{ .val = 1.000000e-183, .off = -5.522105321379546765e-201 }, - HP{ .val = 1.000000e-184, .off = -5.777891238658996019e-201 }, - HP{ .val = 1.000000e-185, .off = 7.542096444923057046e-203 }, - HP{ .val = 1.000000e-186, .off = 8.919335748431433483e-203 }, - HP{ .val = 1.000000e-187, .off = -1.287071881492476028e-204 }, - HP{ .val = 1.000000e-188, .off = 5.091932887209967018e-205 }, - HP{ .val = 1.000000e-189, .off = -6.868701054107114024e-206 }, - HP{ .val = 1.000000e-190, .off = -1.885103578558330118e-207 }, - HP{ .val = 1.000000e-191, .off = -1.885103578558330205e-208 }, - HP{ .val = 1.000000e-192, .off = -9.671974634103305058e-209 }, - HP{ .val = 1.000000e-193, .off = -4.805180224387695640e-210 }, - HP{ .val = 1.000000e-194, .off = -1.763433718315439838e-211 }, - HP{ .val = 1.000000e-195, .off = -9.367799983496079132e-212 }, - HP{ .val = 1.000000e-196, .off = -4.615071067758179837e-213 }, - HP{ .val = 1.000000e-197, .off = 1.325840076914194777e-214 }, - HP{ .val = 1.000000e-198, .off = 8.751979007754662425e-215 }, - HP{ .val = 1.000000e-199, .off = 1.789973760091724198e-216 }, - HP{ .val = 1.000000e-200, .off = 1.789973760091724077e-217 }, - HP{ .val = 1.000000e-201, .off = 5.416018159916171171e-218 }, - HP{ .val = 1.000000e-202, .off = -3.649092839644947067e-219 }, - HP{ .val = 1.000000e-203, .off = -3.649092839644947067e-220 }, - HP{ .val = 1.000000e-204, .off = -1.080338554413850956e-222 }, - HP{ .val = 1.000000e-205, .off = -1.080338554413850841e-223 }, - HP{ .val = 1.000000e-206, .off = -2.874486186850417807e-223 }, - HP{ .val = 1.000000e-207, .off = 7.499710055933455072e-224 }, - HP{ .val = 1.000000e-208, .off = -9.790617015372999087e-225 }, - HP{ .val = 1.000000e-209, .off = -4.387389805589732612e-226 }, - HP{ .val = 1.000000e-210, .off = -4.387389805589732612e-227 }, - HP{ .val = 1.000000e-211, .off = -8.608661063232909897e-228 }, - HP{ .val = 1.000000e-212, .off = 4.582811616902018972e-229 }, - HP{ .val = 1.000000e-213, .off = 4.582811616902019155e-230 }, - HP{ .val = 1.000000e-214, .off = 8.705146829444184930e-231 }, - HP{ .val = 1.000000e-215, .off = -4.177150709750081830e-232 }, - HP{ .val = 1.000000e-216, .off = -4.177150709750082366e-233 }, - HP{ .val = 1.000000e-217, .off = -8.202868690748290237e-234 }, - HP{ .val = 1.000000e-218, .off = -3.170721214500530119e-235 }, - HP{ .val = 1.000000e-219, .off = -3.170721214500529857e-236 }, - HP{ .val = 1.000000e-220, .off = 7.606440013180328441e-238 }, - HP{ .val = 1.000000e-221, .off = -1.696459258568569049e-238 }, - HP{ .val = 1.000000e-222, .off = -4.767838333426821244e-239 }, - HP{ .val = 1.000000e-223, .off = 2.910609353718809138e-240 }, - HP{ .val = 1.000000e-224, .off = -1.888420450747209784e-241 }, - HP{ .val = 1.000000e-225, .off = 4.110366804835314035e-242 }, - HP{ .val = 1.000000e-226, .off = 7.859608839574391006e-243 }, - HP{ .val = 1.000000e-227, .off = 5.516332567862468419e-244 }, - HP{ .val = 1.000000e-228, .off = -3.270953451057244613e-245 }, - HP{ .val = 1.000000e-229, .off = -6.932322625607124670e-246 }, - HP{ .val = 1.000000e-230, .off = -4.643966891513449762e-247 }, - HP{ .val = 1.000000e-231, .off = 1.076922443720738305e-248 }, - HP{ .val = 1.000000e-232, .off = -2.498633390800628939e-249 }, - HP{ .val = 1.000000e-233, .off = 4.205533798926934891e-250 }, - HP{ .val = 1.000000e-234, .off = 4.205533798926934891e-251 }, - HP{ .val = 1.000000e-235, .off = 4.205533798926934697e-252 }, - HP{ .val = 1.000000e-236, .off = -4.523850562697497656e-253 }, - HP{ .val = 1.000000e-237, .off = 9.320146633177728298e-255 }, - HP{ .val = 1.000000e-238, .off = 9.320146633177728062e-256 }, - HP{ .val = 1.000000e-239, .off = -7.592774752331086440e-256 }, - HP{ .val = 1.000000e-240, .off = 3.063212017229987840e-257 }, - HP{ .val = 1.000000e-241, .off = 3.063212017229987562e-258 }, - HP{ .val = 1.000000e-242, .off = 3.063212017229987562e-259 }, - HP{ .val = 1.000000e-243, .off = 4.616527473176159842e-261 }, - HP{ .val = 1.000000e-244, .off = 6.965550922098544975e-261 }, - HP{ .val = 1.000000e-245, .off = 6.965550922098544749e-262 }, - HP{ .val = 1.000000e-246, .off = 4.424965697574744679e-263 }, - HP{ .val = 1.000000e-247, .off = -1.926497363734756420e-264 }, - HP{ .val = 1.000000e-248, .off = 2.043167049583681740e-265 }, - HP{ .val = 1.000000e-249, .off = -5.399953725388390154e-266 }, - HP{ .val = 1.000000e-250, .off = -5.399953725388389982e-267 }, - HP{ .val = 1.000000e-251, .off = -1.523328321757102663e-268 }, - HP{ .val = 1.000000e-252, .off = 5.745344310051561161e-269 }, - HP{ .val = 1.000000e-253, .off = -6.369110076296211879e-270 }, - HP{ .val = 1.000000e-254, .off = 8.773957906638504842e-271 }, - HP{ .val = 1.000000e-255, .off = -6.904595826956931908e-273 }, - HP{ .val = 1.000000e-256, .off = 2.267170882721243669e-273 }, - HP{ .val = 1.000000e-257, .off = 2.267170882721243669e-274 }, - HP{ .val = 1.000000e-258, .off = 4.577819683828225398e-275 }, - HP{ .val = 1.000000e-259, .off = -6.975424321706684210e-276 }, - HP{ .val = 1.000000e-260, .off = 3.855741933482293648e-277 }, - HP{ .val = 1.000000e-261, .off = 1.599248963651256552e-278 }, - HP{ .val = 1.000000e-262, .off = -1.221367248637539543e-279 }, - HP{ .val = 1.000000e-263, .off = -1.221367248637539494e-280 }, - HP{ .val = 1.000000e-264, .off = -1.221367248637539647e-281 }, - HP{ .val = 1.000000e-265, .off = 1.533140771175737943e-282 }, - HP{ .val = 1.000000e-266, .off = 1.533140771175737895e-283 }, - HP{ .val = 1.000000e-267, .off = 1.533140771175738074e-284 }, - HP{ .val = 1.000000e-268, .off = 4.223090009274641634e-285 }, - HP{ .val = 1.000000e-269, .off = 4.223090009274641634e-286 }, - HP{ .val = 1.000000e-270, .off = -4.183001359784432924e-287 }, - HP{ .val = 1.000000e-271, .off = 3.697709298708449474e-288 }, - HP{ .val = 1.000000e-272, .off = 6.981338739747150474e-289 }, - HP{ .val = 1.000000e-273, .off = -9.436808465446354751e-290 }, - HP{ .val = 1.000000e-274, .off = 3.389869038611071740e-291 }, - HP{ .val = 1.000000e-275, .off = 6.596538414625427829e-292 }, - HP{ .val = 1.000000e-276, .off = -9.436808465446354618e-293 }, - HP{ .val = 1.000000e-277, .off = 3.089243784609725523e-294 }, - HP{ .val = 1.000000e-278, .off = 6.220756847123745836e-295 }, - HP{ .val = 1.000000e-279, .off = -5.522417137303829470e-296 }, - HP{ .val = 1.000000e-280, .off = 4.263561183052483059e-297 }, - HP{ .val = 1.000000e-281, .off = -1.852675267170212272e-298 }, - HP{ .val = 1.000000e-282, .off = -1.852675267170212378e-299 }, - HP{ .val = 1.000000e-283, .off = 5.314789322934508480e-300 }, - HP{ .val = 1.000000e-284, .off = -3.644541414696392675e-301 }, - HP{ .val = 1.000000e-285, .off = -7.377595888709267777e-302 }, - HP{ .val = 1.000000e-286, .off = -5.044436842451220838e-303 }, - HP{ .val = 1.000000e-287, .off = -2.127988034628661760e-304 }, - HP{ .val = 1.000000e-288, .off = -5.773549044406860911e-305 }, - HP{ .val = 1.000000e-289, .off = -1.216597782184112068e-306 }, - HP{ .val = 1.000000e-290, .off = -6.912786859962547924e-307 }, - HP{ .val = 1.000000e-291, .off = 3.767567660872018813e-308 }, -}; diff --git a/lib/std/fmt/ryu128.zig b/lib/std/fmt/ryu128.zig new file mode 100644 index 000000000000..1350d556aa3c --- /dev/null +++ b/lib/std/fmt/ryu128.zig @@ -0,0 +1,959 @@ +//! This file implements the ryu floating point conversion algorithm: +//! https://dl.acm.org/doi/pdf/10.1145/3360595 + +const std = @import("std"); + +const special_exponent = 0x7fffffff; + +/// Any buffer used for `format` must be at least this large. This is asserted. A runtime check will +/// additionally be performed if more bytes are required. +pub const min_buffer_size = 53; + +/// Returns the minimum buffer size needed to print every float of a specific type and format. +pub fn bufferSize(comptime mode: Format, comptime T: type) comptime_int { + comptime std.debug.assert(@typeInfo(T) == .Float); + return switch (mode) { + .scientific => 53, + // Based on minimum subnormal values. + .decimal => switch (@bitSizeOf(T)) { + 16 => @max(15, min_buffer_size), + 32 => 55, + 64 => 347, + 80 => 4996, + 128 => 5011, + else => unreachable, + }, + }; +} + +pub const RyuError = error{ + BufferTooSmall, +}; + +pub const Format = enum { + scientific, + decimal, +}; + +pub const FormatOptions = struct { + mode: Format = .scientific, + precision: ?usize = null, +}; + +/// Format a floating-point value and write it to buffer. Returns a slice to the buffer containing +/// the string representation. +/// +/// Full precision is the default. Any full precision float can be reparsed with std.fmt.parseFloat +/// unambiguously. +/// +/// Scientific mode is recommended generally as the output is more compact and any type can be +/// written in full precision using a buffer of only `min_buffer_size`. +/// +/// When printing full precision decimals, use `bufferSize` to get the required space. It is +/// recommended to bound decimal output with a fixed precision to reduce the required buffer size. +pub fn format(buf: []u8, v_: anytype, options: FormatOptions) RyuError![]const u8 { + const v = switch (@TypeOf(v_)) { + // comptime_float internally is a f128; this preserves precision. + comptime_float => @as(f128, v_), + else => v_, + }; + + const T = @TypeOf(v); + comptime std.debug.assert(@typeInfo(T) == .Float); + const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } }); + + const has_explicit_leading_bit = std.math.floatMantissaBits(T) - std.math.floatFractionalBits(T) != 0; + const d = binaryToDecimal(@as(I, @bitCast(v)), std.math.floatMantissaBits(T), std.math.floatExponentBits(T), has_explicit_leading_bit); + + return switch (options.mode) { + .scientific => formatScientific(buf, d, options.precision), + .decimal => formatDecimal(buf, d, options.precision), + }; +} + +pub const FloatDecimal128 = struct { + mantissa: u128, + exponent: i32, + sign: bool, +}; + +fn copySpecialStr(buf: []u8, f: FloatDecimal128) []const u8 { + if (f.sign) { + buf[0] = '-'; + } + const offset: usize = @intFromBool(f.sign); + if (f.mantissa != 0) { + @memcpy(buf[offset..][0..3], "nan"); + return buf[0 .. 3 + offset]; + } + @memcpy(buf[offset..][0..3], "inf"); + return buf[0 .. 3 + offset]; +} + +fn writeDecimal(buf: []u8, value: anytype, count: usize) void { + var i: usize = 0; + + while (i + 2 < count) : (i += 2) { + const c: u8 = @intCast(value.* % 100); + value.* /= 100; + const d = std.fmt.digits2(c); + buf[count - i - 1] = d[1]; + buf[count - i - 2] = d[0]; + } + + while (i < count) : (i += 1) { + const c: u8 = @intCast(value.* % 10); + value.* /= 10; + buf[count - i - 1] = '0' + c; + } +} + +fn isPowerOf10(n_: u128) bool { + var n = n_; + while (n != 0) : (n /= 10) { + if (n % 10 != 0) return false; + } + return true; +} + +const RoundMode = enum { + /// 1234.56 = precision 2 + decimal, + /// 1.23456e3 = precision 5 + scientific, +}; + +fn round(f: FloatDecimal128, mode: RoundMode, precision: usize) FloatDecimal128 { + var round_digit: usize = 0; + var output = f.mantissa; + var exp = f.exponent; + const olength = decimalLength(output); + + switch (mode) { + .decimal => { + if (f.exponent >= 0) { + round_digit = (olength - 1) + precision + @as(usize, @intCast(f.exponent)); + } else { + const min_exp_required = @as(usize, @intCast(-f.exponent)); + if (precision + olength > min_exp_required) { + round_digit = precision + olength - min_exp_required; + } + } + }, + .scientific => { + round_digit = 1 + precision; + }, + } + + if (round_digit < olength) { + var nlength = olength; + for (round_digit + 1..olength) |_| { + output /= 10; + exp += 1; + nlength -= 1; + } + + if (output % 10 >= 5) { + output /= 10; + output += 1; + exp += 1; + + // e.g. 9999 -> 10000 + if (isPowerOf10(output)) { + output /= 10; + exp += 1; + } + } + } + + return .{ + .mantissa = output, + .exponent = exp, + .sign = f.sign, + }; +} + +/// Write a FloatDecimal128 to a buffer in scientific form. +/// +/// The buffer provided must be greater than `min_buffer_size` in length. If no precision is +/// specified, this function will never return an error. If a precision is specified, up to +/// `8 + precision` bytes will be written to the buffer. An error will be returned if the content +/// will not fit. +/// +/// It is recommended to bound decimal formatting with an exact precision. +pub fn formatScientific(buf: []u8, f_: FloatDecimal128, precision: ?usize) RyuError![]const u8 { + std.debug.assert(buf.len >= min_buffer_size); + var f = f_; + + if (f.exponent == special_exponent) { + return copySpecialStr(buf, f); + } + + if (precision) |prec| { + f = round(f, .scientific, prec); + } + + var output = f.mantissa; + const olength = decimalLength(output); + + if (precision) |prec| { + // fixed bound: sign(1) + leading_digit(1) + point(1) + exp_sign(1) + exp_max(4) + const req_bytes = 8 + prec; + if (buf.len < req_bytes) { + return error.BufferTooSmall; + } + } + + // Step 5: Print the scientific representation + var index: usize = 0; + if (f.sign) { + buf[index] = '-'; + index += 1; + } + + // 1.12345 + writeDecimal(buf[index + 2 ..], &output, olength - 1); + buf[index] = '0' + @as(u8, @intCast(output % 10)); + buf[index + 1] = '.'; + index += 2; + const dp_index = index; + if (olength > 1) index += olength - 1 else index -= 1; + + if (precision) |prec| { + index += @intFromBool(olength == 1); + if (prec > olength - 1) { + const len = prec - (olength - 1); + @memset(buf[index..][0..len], '0'); + index += len; + } else { + index = dp_index + prec - @intFromBool(prec == 0); + } + } + + // e100 + buf[index] = 'e'; + index += 1; + var exp = f.exponent + @as(i32, @intCast(olength)) - 1; + if (exp < 0) { + buf[index] = '-'; + index += 1; + exp = -exp; + } + var uexp: u32 = @intCast(exp); + const elength = decimalLength(uexp); + writeDecimal(buf[index..], &uexp, elength); + index += elength; + + return buf[0..index]; +} + +/// Write a FloatDecimal128 to a buffer in decimal form. +/// +/// The buffer provided must be greater than `min_buffer_size` bytes in length. If no precision is +/// specified, this may still return an error. If precision is specified, `2 + precision` bytes will +/// always be written. +pub fn formatDecimal(buf: []u8, f_: FloatDecimal128, precision: ?usize) RyuError![]const u8 { + std.debug.assert(buf.len >= min_buffer_size); + var f = f_; + + if (f.exponent == special_exponent) { + return copySpecialStr(buf, f); + } + + if (precision) |prec| { + f = round(f, .decimal, prec); + } + + var output = f.mantissa; + const olength = decimalLength(output); + + // fixed bound: leading_digit(1) + point(1) + const req_bytes = if (f.exponent >= 0) + 2 + @abs(f.exponent) + olength + (precision orelse 0) + else + 2 + @max(@abs(f.exponent) + olength, precision orelse 0); + if (buf.len < req_bytes) { + return error.BufferTooSmall; + } + + // Step 5: Print the decimal representation + var index: usize = 0; + if (f.sign) { + buf[index] = '-'; + index += 1; + } + + const dp_offset = f.exponent + cast_i32(olength); + if (dp_offset <= 0) { + // 0.000001234 + buf[index] = '0'; + buf[index + 1] = '.'; + index += 2; + const dp_index = index; + + const dp_poffset: u32 = @intCast(-dp_offset); + @memset(buf[index..][0..dp_poffset], '0'); + index += dp_poffset; + writeDecimal(buf[index..], &output, olength); + index += olength; + + if (precision) |prec| { + const dp_written = index - dp_index; + if (prec > dp_written) { + @memset(buf[index..][0 .. prec - dp_written], '0'); + } + index = dp_index + prec - @intFromBool(prec == 0); + } + } else { + // 123456000 + const dp_uoffset: usize = @intCast(dp_offset); + if (dp_uoffset >= olength) { + writeDecimal(buf[index..], &output, olength); + index += olength; + @memset(buf[index..][0 .. dp_uoffset - olength], '0'); + index += dp_uoffset - olength; + + if (precision) |prec| { + if (prec != 0) { + buf[index] = '.'; + index += 1; + @memset(buf[index..][0..prec], '0'); + index += prec; + } + } + } else { + // 12345.6789 + writeDecimal(buf[index + dp_uoffset + 1 ..], &output, olength - dp_uoffset); + buf[index + dp_uoffset] = '.'; + const dp_index = index + dp_uoffset + 1; + writeDecimal(buf[index..], &output, dp_uoffset); + index += olength + 1; + + if (precision) |prec| { + const dp_written = olength - dp_uoffset; + if (prec > dp_written) { + @memset(buf[index..][0 .. prec - dp_written], '0'); + } + index = dp_index + prec - @intFromBool(prec == 0); + } + } + } + + return buf[0..index]; +} + +fn cast_i32(v: anytype) i32 { + return @intCast(v); +} + +/// Convert a binary float representation to decimal. +pub fn binaryToDecimal(bits: u128, mantissa_bits: u7, exponent_bits: u5, explicit_leading_bit: bool) FloatDecimal128 { + const bias = (@as(u32, 1) << (exponent_bits - 1)) - 1; + const ieee_sign = ((bits >> (mantissa_bits + exponent_bits)) & 1) != 0; + const ieee_mantissa = bits & ((@as(u128, 1) << mantissa_bits) - 1); + const ieee_exponent: u32 = @intCast((bits >> mantissa_bits) & ((@as(u128, 1) << exponent_bits) - 1)); + + if (ieee_exponent == 0 and ieee_mantissa == 0) { + return .{ + .mantissa = 0, + .exponent = 0, + .sign = ieee_sign, + }; + } + if (ieee_exponent == ((@as(u32, 1) << exponent_bits) - 1)) { + return .{ + .mantissa = if (explicit_leading_bit) ieee_mantissa & ((@as(u128, 1) << (mantissa_bits - 1)) - 1) else ieee_mantissa, + .exponent = 0x7fffffff, + .sign = ieee_sign, + }; + } + + var e2: i32 = undefined; + var m2: u128 = undefined; + if (explicit_leading_bit) { + if (ieee_exponent == 0) { + e2 = 1 - cast_i32(bias) - cast_i32(mantissa_bits) + 1 - 2; + } else { + e2 = cast_i32(ieee_exponent) - cast_i32(bias) - cast_i32(mantissa_bits) + 1 - 2; + } + m2 = ieee_mantissa; + } else { + if (ieee_exponent == 0) { + e2 = 1 - cast_i32(bias) - cast_i32(mantissa_bits) - 2; + m2 = ieee_mantissa; + } else { + e2 = cast_i32(ieee_exponent) - cast_i32(bias) - cast_i32(mantissa_bits) - 2; + m2 = (@as(u128, 1) << mantissa_bits) | ieee_mantissa; + } + } + const even = (m2 & 1) == 0; + const accept_bounds = even; + + // Step 2: Determine the interval of legal decimal representations. + const mv = 4 * m2; + const mm_shift: u1 = @intFromBool((ieee_mantissa != if (explicit_leading_bit) (@as(u128, 1) << (mantissa_bits - 1)) else 0) or (ieee_exponent == 0)); + + // Step 3: Convert to a decimal power base using 128-bit arithmetic. + var vr: u128 = undefined; + var vp: u128 = undefined; + var vm: u128 = undefined; + var e10: i32 = undefined; + var vm_is_trailing_zeros = false; + var vr_is_trailing_zeros = false; + if (e2 >= 0) { + const q: u32 = log10Pow2(@intCast(e2)) - @intFromBool(e2 > 3); + e10 = cast_i32(q); + const k: i32 = @intCast(FLOAT_128_POW5_INV_BITCOUNT + pow5Bits(q) - 1); + const i: u32 = @intCast(-e2 + cast_i32(q) + k); + + const pow5 = computeInvPow5(q); + vr = mulShift(4 * m2, &pow5, i); + vp = mulShift(4 * m2 + 2, &pow5, i); + vm = mulShift(4 * m2 - 1 - mm_shift, &pow5, i); + + if (q <= 55) { + if (mv % 5 == 0) { + vr_is_trailing_zeros = multipleOfPowerOf5(mv, q -% 1); + } else if (accept_bounds) { + vm_is_trailing_zeros = multipleOfPowerOf5(mv - 1 - mm_shift, q); + } else { + vp -= @intFromBool(multipleOfPowerOf5(mv + 2, q)); + } + } + } else { + const q: u32 = log10Pow5(@intCast(-e2)) - @intFromBool(-e2 > 1); + e10 = cast_i32(q) + e2; + const i: i32 = -e2 - cast_i32(q); + const k: i32 = cast_i32(pow5Bits(@intCast(i))) - FLOAT_128_POW5_BITCOUNT; + const j: u32 = @intCast(cast_i32(q) - k); + + const pow5 = computePow5(@intCast(i)); + vr = mulShift(4 * m2, &pow5, j); + vp = mulShift(4 * m2 + 2, &pow5, j); + vm = mulShift(4 * m2 - 1 - mm_shift, &pow5, j); + + if (q <= 1) { + vr_is_trailing_zeros = true; + if (accept_bounds) { + vm_is_trailing_zeros = mm_shift == 1; + } else { + vp -= 1; + } + } else if (q < 127) { + vr_is_trailing_zeros = multipleOfPowerOf2(mv, q - 1); + } + } + + // Step 4: Find the shortest decimal representation in the interval of legal representations. + var removed: u32 = 0; + var last_removed_digit: u8 = 0; + + while (vp / 10 > vm / 10) { + vm_is_trailing_zeros = vm_is_trailing_zeros and vm % 10 == 0; + vr_is_trailing_zeros = vr_is_trailing_zeros and last_removed_digit == 0; + last_removed_digit = @intCast(vr % 10); + vr /= 10; + vp /= 10; + vm /= 10; + removed += 1; + } + + if (vm_is_trailing_zeros) { + while (vm % 10 == 0) { + vr_is_trailing_zeros = vr_is_trailing_zeros and last_removed_digit == 0; + last_removed_digit = @intCast(vr % 10); + vr /= 10; + vp /= 10; + vm /= 10; + removed += 1; + } + } + + if (vr_is_trailing_zeros and (last_removed_digit == 5) and (vr % 2 == 0)) { + last_removed_digit = 4; + } + + return .{ + .mantissa = vr + @intFromBool((vr == vm and (!accept_bounds or !vm_is_trailing_zeros)) or last_removed_digit >= 5), + .exponent = e10 + cast_i32(removed), + .sign = ieee_sign, + }; +} + +fn decimalLength(v: u128) u32 { + const LARGEST_POW10 = (@as(u128, 5421010862427522170) << 64) | 687399551400673280; + var p10 = LARGEST_POW10; + var i: u32 = 39; + while (i > 0) : (i -= 1) { + if (v >= p10) return i; + p10 /= 10; + } + return 1; +} + +// floor(log_10(2^e)) +fn log10Pow2(e: u32) u32 { + std.debug.assert(e <= 1 << 15); + return @intCast((@as(u64, @intCast(e)) * 169464822037455) >> 49); +} + +// floor(log_10(5^e)) +fn log10Pow5(e: u32) u32 { + std.debug.assert(e <= 1 << 15); + return @intCast((@as(u64, @intCast(e)) * 196742565691928) >> 48); +} + +// if (e == 0) 1 else ceil(log_2(5^e)) +fn pow5Bits(e: u32) u32 { + std.debug.assert(e <= 1 << 15); + return @intCast(((@as(u64, @intCast(e)) * 163391164108059) >> 46) + 1); +} + +fn pow5Factor(value_: u128) u32 { + var count: u32 = 0; + var value = value_; + while (value > 0) : ({ + count += 1; + value /= 5; + }) { + if (value % 5 != 0) return count; + } + return 0; +} + +fn multipleOfPowerOf5(value: u128, p: u32) bool { + return pow5Factor(value) >= p; +} + +fn multipleOfPowerOf2(value: u128, p: u32) bool { + return (value & ((@as(u128, 1) << @as(u7, @intCast(p))) - 1)) == 0; +} + +fn computeInvPow5(i: u32) [4]u64 { + const base = (i + POW5_TABLE_SIZE - 1) / POW5_TABLE_SIZE; + const base2 = base * POW5_TABLE_SIZE; + const mul = &GENERIC_POW5_INV_SPLIT[base]; // 1 / 5^base2 + if (i == base2) { + return .{ mul[0] + 1, mul[1], mul[2], mul[3] }; + } else { + const offset = base2 - i; + const m = &GENERIC_POW5_TABLE[offset]; // 5^offset + const delta = pow5Bits(base2) - pow5Bits(i); + + const shift: u6 = @intCast(2 * (i % 32)); + const corr: u32 = @intCast(((POW5_INV_ERRORS[i / 32] >> shift) & 3) + 1); + return mul_128_256_shift(m, mul, delta, corr); + } +} + +fn computePow5(i: u32) [4]u64 { + const base = i / POW5_TABLE_SIZE; + const base2 = base * POW5_TABLE_SIZE; + const mul = &GENERIC_POW5_SPLIT[base]; + if (i == base2) { + return mul.*; + } else { + const offset = i - base2; + const m = &GENERIC_POW5_TABLE[offset]; + const delta = pow5Bits(i) - pow5Bits(base2); + + const shift: u6 = @intCast(2 * (i % 32)); + const corr: u32 = @intCast((POW5_ERRORS[i / 32] >> shift) & 3); + return mul_128_256_shift(m, mul, delta, corr); + } +} + +fn mulShift(m: u128, mul: *const [4]u64, j: u32) u128 { + std.debug.assert(j > 128); + const a: [2]u64 = .{ @truncate(m), @truncate(m >> 64) }; + const r = mul_128_256_shift(&a, mul, j, 0); + return (@as(u128, r[1]) << 64) | r[0]; +} + +fn mul_128_256_shift(a: *const [2]u64, b: *const [4]u64, shift: u32, corr: u32) [4]u64 { + std.debug.assert(shift > 0); + std.debug.assert(shift < 256); + + const b00 = @as(u128, a[0]) * b[0]; + const b01 = @as(u128, a[0]) * b[1]; + const b02 = @as(u128, a[0]) * b[2]; + const b03 = @as(u128, a[0]) * b[3]; + const b10 = @as(u128, a[1]) * b[0]; + const b11 = @as(u128, a[1]) * b[1]; + const b12 = @as(u128, a[1]) * b[2]; + const b13 = @as(u128, a[1]) * b[3]; + + const s0 = b00; + const s1 = b01 +% b10; + const c1: u128 = @intFromBool(s1 < b01); + const s2 = b02 +% b11; + const c2: u128 = @intFromBool(s2 < b02); + const s3 = b03 +% b12; + const c3: u128 = @intFromBool(s3 < b03); + + const p0 = s0 +% (s1 << 64); + const d0: u128 = @intFromBool(p0 < b00); + const q1 = s2 +% (s1 >> 64) +% (s3 << 64); + const d1: u128 = @intFromBool(q1 < s2); + const p1 = q1 +% (c1 << 64) +% d0; + const d2: u128 = @intFromBool(p1 < q1); + const p2 = b13 +% (s3 >> 64) +% c2 +% (c3 << 64) +% d1 +% d2; + + var r0: u128 = undefined; + var r1: u128 = undefined; + if (shift < 128) { + const cshift: u7 = @intCast(shift); + const sshift: u7 = @intCast(128 - shift); + r0 = corr +% ((p0 >> cshift) | (p1 << sshift)); + r1 = ((p1 >> cshift) | (p2 << sshift)) +% @intFromBool(r0 < corr); + } else if (shift == 128) { + r0 = corr +% p1; + r1 = p2 +% @intFromBool(r0 < corr); + } else { + const ashift: u7 = @intCast(shift - 128); + const sshift: u7 = @intCast(256 - shift); + r0 = corr +% ((p1 >> ashift) | (p2 << sshift)); + r1 = (p2 >> ashift) +% @intFromBool(r0 < corr); + } + + return .{ @truncate(r0), @truncate(r0 >> 64), @truncate(r1), @truncate(r1 >> 64) }; +} + +// zig fmt: off +// +// 4.5KiB of tables. + +const FLOAT_128_POW5_INV_BITCOUNT = 249; +const FLOAT_128_POW5_BITCOUNT = 249; +const POW5_TABLE_SIZE = 56; + +const GENERIC_POW5_TABLE: [POW5_TABLE_SIZE][2]u64 = .{ + .{ 1, 0 }, + .{ 5, 0 }, + .{ 25, 0 }, + .{ 125, 0 }, + .{ 625, 0 }, + .{ 3125, 0 }, + .{ 15625, 0 }, + .{ 78125, 0 }, + .{ 390625, 0 }, + .{ 1953125, 0 }, + .{ 9765625, 0 }, + .{ 48828125, 0 }, + .{ 244140625, 0 }, + .{ 1220703125, 0 }, + .{ 6103515625, 0 }, + .{ 30517578125, 0 }, + .{ 152587890625, 0 }, + .{ 762939453125, 0 }, + .{ 3814697265625, 0 }, + .{ 19073486328125, 0 }, + .{ 95367431640625, 0 }, + .{ 476837158203125, 0 }, + .{ 2384185791015625, 0 }, + .{ 11920928955078125, 0 }, + .{ 59604644775390625, 0 }, + .{ 298023223876953125, 0 }, + .{ 1490116119384765625, 0 }, + .{ 7450580596923828125, 0 }, + .{ 359414837200037393, 2 }, + .{ 1797074186000186965, 10 }, + .{ 8985370930000934825, 50 }, + .{ 8033366502585570893, 252 }, + .{ 3273344365508751233, 1262 }, + .{ 16366721827543756165, 6310 }, + .{ 8046632842880574361, 31554 }, + .{ 3339676066983768573, 157772 }, + .{ 16698380334918842865, 788860 }, + .{ 9704925379756007861, 3944304 }, + .{ 11631138751360936073, 19721522 }, + .{ 2815461535676025517, 98607613 }, + .{ 14077307678380127585, 493038065 }, + .{ 15046306170771983077, 2465190328 }, + .{ 1444554559021708921, 12325951644 }, + .{ 7222772795108544605, 61629758220 }, + .{ 17667119901833171409, 308148791101 }, + .{ 14548623214327650581, 1540743955509 }, + .{ 17402883850509598057, 7703719777548 }, + .{ 13227442957709783821, 38518598887744 }, + .{ 10796982567420264257, 192592994438723 }, + .{ 17091424689682218053, 962964972193617 }, + .{ 11670147153572883801, 4814824860968089 }, + .{ 3010503546735764157, 24074124304840448 }, + .{ 15052517733678820785, 120370621524202240 }, + .{ 1475612373555897461, 601853107621011204 }, + .{ 7378061867779487305, 3009265538105056020 }, + .{ 18443565265187884909, 15046327690525280101 }, +}; + +const GENERIC_POW5_SPLIT: [89][4]u64 = .{ + .{ 0, 0, 0, 72057594037927936 }, + .{ 0, 5206161169240293376, 4575641699882439235, 73468396926392969 }, + .{ 3360510775605221349, 6983200512169538081, 4325643253124434363, 74906821675075173 }, + .{ 11917660854915489451, 9652941469841108803, 946308467778435600, 76373409087490117 }, + .{ 1994853395185689235, 16102657350889591545, 6847013871814915412, 77868710555449746 }, + .{ 958415760277438274, 15059347134713823592, 7329070255463483331, 79393288266368765 }, + .{ 2065144883315240188, 7145278325844925976, 14718454754511147343, 80947715414629833 }, + .{ 8980391188862868935, 13709057401304208685, 8230434828742694591, 82532576417087045 }, + .{ 432148644612782575, 7960151582448466064, 12056089168559840552, 84148467132788711 }, + .{ 484109300864744403, 15010663910730448582, 16824949663447227068, 85795995087002057 }, + .{ 14793711725276144220, 16494403799991899904, 10145107106505865967, 87475779699624060 }, + .{ 15427548291869817042, 12330588654550505203, 13980791795114552342, 89188452518064298 }, + .{ 9979404135116626552, 13477446383271537499, 14459862802511591337, 90934657454687378 }, + .{ 12385121150303452775, 9097130814231585614, 6523855782339765207, 92715051028904201 }, + .{ 1822931022538209743, 16062974719797586441, 3619180286173516788, 94530302614003091 }, + .{ 12318611738248470829, 13330752208259324507, 10986694768744162601, 96381094688813589 }, + .{ 13684493829640282333, 7674802078297225834, 15208116197624593182, 98268123094297527 }, + .{ 5408877057066295332, 6470124174091971006, 15112713923117703147, 100192097295163851 }, + .{ 11407083166564425062, 18189998238742408185, 4337638702446708282, 102153740646605557 }, + .{ 4112405898036935485, 924624216579956435, 14251108172073737125, 104153790666259019 }, + .{ 16996739107011444789, 10015944118339042475, 2395188869672266257, 106192999311487969 }, + .{ 4588314690421337879, 5339991768263654604, 15441007590670620066, 108272133262096356 }, + .{ 2286159977890359825, 14329706763185060248, 5980012964059367667, 110391974208576409 }, + .{ 9654767503237031099, 11293544302844823188, 11739932712678287805, 112553319146000238 }, + .{ 11362964448496095896, 7990659682315657680, 251480263940996374, 114756980673665505 }, + .{ 1423410421096377129, 14274395557581462179, 16553482793602208894, 117003787300607788 }, + .{ 2070444190619093137, 11517140404712147401, 11657844572835578076, 119294583757094535 }, + .{ 7648316884775828921, 15264332483297977688, 247182277434709002, 121630231312217685 }, + .{ 17410896758132241352, 10923914482914417070, 13976383996795783649, 124011608097704390 }, + .{ 9542674537907272703, 3079432708831728956, 14235189590642919676, 126439609438067572 }, + .{ 10364666969937261816, 8464573184892924210, 12758646866025101190, 128915148187220428 }, + .{ 14720354822146013883, 11480204489231511423, 7449876034836187038, 131439155071681461 }, + .{ 1692907053653558553, 17835392458598425233, 1754856712536736598, 134012579040499057 }, + .{ 5620591334531458755, 11361776175667106627, 13350215315297937856, 136636387622027174 }, + .{ 17455759733928092601, 10362573084069962561, 11246018728801810510, 139311567287686283 }, + .{ 2465404073814044982, 17694822665274381860, 1509954037718722697, 142039123822846312 }, + .{ 2152236053329638369, 11202280800589637091, 16388426812920420176, 72410041352485523 }, + .{ 17319024055671609028, 10944982848661280484, 2457150158022562661, 73827744744583080 }, + .{ 17511219308535248024, 5122059497846768077, 2089605804219668451, 75273205100637900 }, + .{ 10082673333144031533, 14429008783411894887, 12842832230171903890, 76746965869337783 }, + .{ 16196653406315961184, 10260180891682904501, 10537411930446752461, 78249581139456266 }, + .{ 15084422041749743389, 234835370106753111, 16662517110286225617, 79781615848172976 }, + .{ 8199644021067702606, 3787318116274991885, 7438130039325743106, 81343645993472659 }, + .{ 12039493937039359765, 9773822153580393709, 5945428874398357806, 82936258850702722 }, + .{ 984543865091303961, 7975107621689454830, 6556665988501773347, 84560053193370726 }, + .{ 9633317878125234244, 16099592426808915028, 9706674539190598200, 86215639518264828 }, + .{ 6860695058870476186, 4471839111886709592, 7828342285492709568, 87903640274981819 }, + .{ 14583324717644598331, 4496120889473451238, 5290040788305728466, 89624690099949049 }, + .{ 18093669366515003715, 12879506572606942994, 18005739787089675377, 91379436055028227 }, + .{ 17997493966862379937, 14646222655265145582, 10265023312844161858, 93168537870790806 }, + .{ 12283848109039722318, 11290258077250314935, 9878160025624946825, 94992668194556404 }, + .{ 8087752761883078164, 5262596608437575693, 11093553063763274413, 96852512843287537 }, + .{ 15027787746776840781, 12250273651168257752, 9290470558712181914, 98748771061435726 }, + .{ 15003915578366724489, 2937334162439764327, 5404085603526796602, 100682155783835929 }, + .{ 5225610465224746757, 14932114897406142027, 2774647558180708010, 102653393903748137 }, + .{ 17112957703385190360, 12069082008339002412, 3901112447086388439, 104663226546146909 }, + .{ 4062324464323300238, 3992768146772240329, 15757196565593695724, 106712409346361594 }, + .{ 5525364615810306701, 11855206026704935156, 11344868740897365300, 108801712734172003 }, + .{ 9274143661888462646, 4478365862348432381, 18010077872551661771, 110931922223466333 }, + .{ 12604141221930060148, 8930937759942591500, 9382183116147201338, 113103838707570263 }, + .{ 14513929377491886653, 1410646149696279084, 587092196850797612, 115318278760358235 }, + .{ 2226851524999454362, 7717102471110805679, 7187441550995571734, 117576074943260147 }, + .{ 5527526061344932763, 2347100676188369132, 16976241418824030445, 119878076118278875 }, + .{ 6088479778147221611, 17669593130014777580, 10991124207197663546, 122225147767136307 }, + .{ 11107734086759692041, 3391795220306863431, 17233960908859089158, 124618172316667879 }, + .{ 7913172514655155198, 17726879005381242552, 641069866244011540, 127058049470587962 }, + .{ 12596991768458713949, 15714785522479904446, 6035972567136116512, 129545696547750811 }, + .{ 16901996933781815980, 4275085211437148707, 14091642539965169063, 132082048827034281 }, + .{ 7524574627987869240, 15661204384239316051, 2444526454225712267, 134668059898975949 }, + .{ 8199251625090479942, 6803282222165044067, 16064817666437851504, 137304702024293857 }, + .{ 4453256673338111920, 15269922543084434181, 3139961729834750852, 139992966499426682 }, + .{ 15841763546372731299, 3013174075437671812, 4383755396295695606, 142733864029230733 }, + .{ 9771896230907310329, 4900659362437687569, 12386126719044266361, 72764212553486967 }, + .{ 9420455527449565190, 1859606122611023693, 6555040298902684281, 74188850200884818 }, + .{ 5146105983135678095, 2287300449992174951, 4325371679080264751, 75641380576797959 }, + .{ 11019359372592553360, 8422686425957443718, 7175176077944048210, 77122349788024458 }, + .{ 11005742969399620716, 4132174559240043701, 9372258443096612118, 78632314633490790 }, + .{ 8887589641394725840, 8029899502466543662, 14582206497241572853, 80171842813591127 }, + .{ 360247523705545899, 12568341805293354211, 14653258284762517866, 81741513143625247 }, + .{ 12314272731984275834, 4740745023227177044, 6141631472368337539, 83341915771415304 }, + .{ 441052047733984759, 7940090120939869826, 11750200619921094248, 84973652399183278 }, + .{ 3436657868127012749, 9187006432149937667, 16389726097323041290, 86637336509772529 }, + .{ 13490220260784534044, 15339072891382896702, 8846102360835316895, 88333593597298497 }, + .{ 4125672032094859833, 158347675704003277, 10592598512749774447, 90063061402315272 }, + .{ 12189928252974395775, 2386931199439295891, 7009030566469913276, 91826390151586454 }, + .{ 9256479608339282969, 2844900158963599229, 11148388908923225596, 93624242802550437 }, + .{ 11584393507658707408, 2863659090805147914, 9873421561981063551, 95457295292572042 }, + .{ 13984297296943171390, 1931468383973130608, 12905719743235082319, 97326236793074198 }, + .{ 5837045222254987499, 10213498696735864176, 14893951506257020749, 99231769968645227 }, +}; + +// Unfortunately, the results are sometimes off by one or two. We use an additional +// lookup table to store those cases and adjust the result. +const POW5_ERRORS: [156]u64 = .{ + 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x9555596400000000, + 0x65a6569525565555, 0x4415551445449655, 0x5105015504144541, 0x65a69969a6965964, + 0x5054955969959656, 0x5105154515554145, 0x4055511051591555, 0x5500514455550115, + 0x0041140014145515, 0x1005440545511051, 0x0014405450411004, 0x0414440010500000, + 0x0044000440010040, 0x5551155000004001, 0x4554555454544114, 0x5150045544005441, + 0x0001111400054501, 0x6550955555554554, 0x1504159645559559, 0x4105055141454545, + 0x1411541410405454, 0x0415555044545555, 0x0014154115405550, 0x1540055040411445, + 0x0000000500000000, 0x5644000000000000, 0x1155555591596555, 0x0410440054569565, + 0x5145100010010005, 0x0555041405500150, 0x4141450455140450, 0x0000000144000140, + 0x5114004001105410, 0x4444100404005504, 0x0414014410001015, 0x5145055155555015, + 0x0141041444445540, 0x0000100451541414, 0x4105041104155550, 0x0500501150451145, + 0x1001050000004114, 0x5551504400141045, 0x5110545410151454, 0x0100001400004040, + 0x5040010111040000, 0x0140000150541100, 0x4400140400104110, 0x5011014405545004, + 0x0000000044155440, 0x0000000010000000, 0x1100401444440001, 0x0040401010055111, + 0x5155155551405454, 0x0444440015514411, 0x0054505054014101, 0x0451015441115511, + 0x1541411401140551, 0x4155104514445110, 0x4141145450145515, 0x5451445055155050, + 0x4400515554110054, 0x5111145104501151, 0x565a655455500501, 0x5565555555525955, + 0x0550511500405695, 0x4415504051054544, 0x6555595965555554, 0x0100915915555655, + 0x5540001510001001, 0x5450051414000544, 0x1405010555555551, 0x5555515555644155, + 0x5555055595496555, 0x5451045004415000, 0x5450510144040144, 0x5554155555556455, + 0x5051555495415555, 0x5555554555555545, 0x0000000010005455, 0x4000005000040000, + 0x5565555555555954, 0x5554559555555505, 0x9645545495552555, 0x4000400055955564, + 0x0040000000000001, 0x4004100100000000, 0x5540040440000411, 0x4565555955545644, + 0x1140659549651556, 0x0100000410010000, 0x5555515400004001, 0x5955545555155255, + 0x5151055545505556, 0x5051454510554515, 0x0501500050415554, 0x5044154005441005, + 0x1455445450550455, 0x0010144055144545, 0x0000401100000004, 0x1050145050000010, + 0x0415004554011540, 0x1000510100151150, 0x0100040400001144, 0x0000000000000000, + 0x0550004400000100, 0x0151145041451151, 0x0000400400005450, 0x0000100044010004, + 0x0100054100050040, 0x0504400005410010, 0x4011410445500105, 0x0000404000144411, + 0x0101504404500000, 0x0000005044400400, 0x0000000014000100, 0x0404440414000000, + 0x5554100410000140, 0x4555455544505555, 0x5454105055455455, 0x0115454155454015, + 0x4404110000045100, 0x4400001100101501, 0x6596955956966a94, 0x0040655955665965, + 0x5554144400100155, 0xa549495401011041, 0x5596555565955555, 0x5569965959549555, + 0x969565a655555456, 0x0000001000000000, 0x0000000040000140, 0x0000040100000000, + 0x1415454400000000, 0x5410415411454114, 0x0400040104000154, 0x0504045000000411, + 0x0000001000000010, 0x5554000000001040, 0x5549155551556595, 0x1455541055515555, + 0x0510555454554541, 0x9555555555540455, 0x6455456555556465, 0x4524565555654514, + 0x5554655255559545, 0x9555455441155556, 0x0000000051515555, 0x0010005040000550, + 0x5044044040000000, 0x1045040440010500, 0x0000400000040000, 0x0000000000000000, +}; + +const GENERIC_POW5_INV_SPLIT: [89][4]u64 = .{ + .{ 0, 0, 0, 144115188075855872 }, + .{ 1573859546583440065, 2691002611772552616, 6763753280790178510, 141347765182270746 }, + .{ 12960290449513840412, 12345512957918226762, 18057899791198622765, 138633484706040742 }, + .{ 7615871757716765416, 9507132263365501332, 4879801712092008245, 135971326161092377 }, + .{ 7869961150745287587, 5804035291554591636, 8883897266325833928, 133360288657597085 }, + .{ 2942118023529634767, 15128191429820565086, 10638459445243230718, 130799390525667397 }, + .{ 14188759758411913794, 5362791266439207815, 8068821289119264054, 128287668946279217 }, + .{ 7183196927902545212, 1952291723540117099, 12075928209936341512, 125824179589281448 }, + .{ 5672588001402349748, 17892323620748423487, 9874578446960390364, 123407996258356868 }, + .{ 4442590541217566325, 4558254706293456445, 10343828952663182727, 121038210542800766 }, + .{ 3005560928406962566, 2082271027139057888, 13961184524927245081, 118713931475986426 }, + .{ 13299058168408384786, 17834349496131278595, 9029906103900731664, 116434285200389047 }, + .{ 5414878118283973035, 13079825470227392078, 17897304791683760280, 114198414639042157 }, + .{ 14609755883382484834, 14991702445765844156, 3269802549772755411, 112005479173303009 }, + .{ 15967774957605076027, 2511532636717499923, 16221038267832563171, 109854654326805788 }, + .{ 9269330061621627145, 3332501053426257392, 16223281189403734630, 107745131455483836 }, + .{ 16739559299223642282, 1873986623300664530, 6546709159471442872, 105676117443544318 }, + .{ 17116435360051202055, 1359075105581853924, 2038341371621886470, 103646834405281051 }, + .{ 17144715798009627550, 3201623802661132408, 9757551605154622431, 101656519392613377 }, + .{ 17580479792687825857, 6546633380567327312, 15099972427870912398, 99704424108241124 }, + .{ 9726477118325522902, 14578369026754005435, 11728055595254428803, 97789814624307808 }, + .{ 134593949518343635, 5715151379816901985, 1660163707976377376, 95911971106466306 }, + .{ 5515914027713859358, 7124354893273815720, 5548463282858794077, 94070187543243255 }, + .{ 6188403395862945512, 5681264392632320838, 15417410852121406654, 92263771480600430 }, + .{ 15908890877468271457, 10398888261125597540, 4817794962769172309, 90492043761593298 }, + .{ 1413077535082201005, 12675058125384151580, 7731426132303759597, 88754338271028867 }, + .{ 1486733163972670293, 11369385300195092554, 11610016711694864110, 87050001685026843 }, + .{ 8788596583757589684, 3978580923851924802, 9255162428306775812, 85378393225389919 }, + .{ 7203518319660962120, 15044736224407683725, 2488132019818199792, 83738884418690858 }, + .{ 4004175967662388707, 18236988667757575407, 15613100370957482671, 82130858859985791 }, + .{ 18371903370586036463, 53497579022921640, 16465963977267203307, 80553711981064899 }, + .{ 10170778323887491315, 1999668801648976001, 10209763593579456445, 79006850823153334 }, + .{ 17108131712433974546, 16825784443029944237, 2078700786753338945, 77489693813976938 }, + .{ 17221789422665858532, 12145427517550446164, 5391414622238668005, 76001670549108934 }, + .{ 4859588996898795878, 1715798948121313204, 3950858167455137171, 74542221577515387 }, + .{ 13513469241795711526, 631367850494860526, 10517278915021816160, 73110798191218799 }, + .{ 11757513142672073111, 2581974932255022228, 17498959383193606459, 143413724438001539 }, + .{ 14524355192525042817, 5640643347559376447, 1309659274756813016, 140659771648132296 }, + .{ 2765095348461978538, 11021111021896007722, 3224303603779962366, 137958702611185230 }, + .{ 12373410389187981037, 13679193545685856195, 11644609038462631561, 135309501808182158 }, + .{ 12813176257562780151, 3754199046160268020, 9954691079802960722, 132711173221007413 }, + .{ 17557452279667723458, 3237799193992485824, 17893947919029030695, 130162739957935629 }, + .{ 14634200999559435155, 4123869946105211004, 6955301747350769239, 127663243886350468 }, + .{ 2185352760627740240, 2864813346878886844, 13049218671329690184, 125211745272516185 }, + .{ 6143438674322183002, 10464733336980678750, 6982925169933978309, 122807322428266620 }, + .{ 1099509117817174576, 10202656147550524081, 754997032816608484, 120449071364478757 }, + .{ 2410631293559367023, 17407273750261453804, 15307291918933463037, 118136105451200587 }, + .{ 12224968375134586697, 1664436604907828062, 11506086230137787358, 115867555084305488 }, + .{ 3495926216898000888, 18392536965197424288, 10992889188570643156, 113642567358547782 }, + .{ 8744506286256259680, 3966568369496879937, 18342264969761820037, 111460305746896569 }, + .{ 7689600520560455039, 5254331190877624630, 9628558080573245556, 109319949786027263 }, + .{ 11862637625618819436, 3456120362318976488, 14690471063106001082, 107220694767852583 }, + .{ 5697330450030126444, 12424082405392918899, 358204170751754904, 105161751436977040 }, + .{ 11257457505097373622, 15373192700214208870, 671619062372033814, 103142345693961148 }, + .{ 16850355018477166700, 1913910419361963966, 4550257919755970531, 101161718304283822 }, + .{ 9670835567561997011, 10584031339132130638, 3060560222974851757, 99219124612893520 }, + .{ 7698686577353054710, 11689292838639130817, 11806331021588878241, 97313834264240819 }, + .{ 12233569599615692137, 3347791226108469959, 10333904326094451110, 95445130927687169 }, + .{ 13049400362825383933, 17142621313007799680, 3790542585289224168, 93612312028186576 }, + .{ 12430457242474442072, 5625077542189557960, 14765055286236672238, 91814688482138969 }, + .{ 4759444137752473128, 2230562561567025078, 4954443037339580076, 90051584438315940 }, + .{ 7246913525170274758, 8910297835195760709, 4015904029508858381, 88322337023761438 }, + .{ 12854430245836432067, 8135139748065431455, 11548083631386317976, 86626296094571907 }, + .{ 4848827254502687803, 4789491250196085625, 3988192420450664125, 84962823991462151 }, + .{ 7435538409611286684, 904061756819742353, 14598026519493048444, 83331295300025028 }, + .{ 11042616160352530997, 8948390828345326218, 10052651191118271927, 81731096615594853 }, + .{ 11059348291563778943, 11696515766184685544, 3783210511290897367, 80161626312626082 }, + .{ 7020010856491885826, 5025093219346041680, 8960210401638911765, 78622294318500592 }, + .{ 17732844474490699984, 7820866704994446502, 6088373186798844243, 77112521891678506 }, + .{ 688278527545590501, 3045610706602776618, 8684243536999567610, 75631741404109150 }, + .{ 2734573255120657297, 3903146411440697663, 9470794821691856713, 74179396127820347 }, + .{ 15996457521023071259, 4776627823451271680, 12394856457265744744, 72754940025605801 }, + .{ 13492065758834518331, 7390517611012222399, 1630485387832860230, 142715675091463768 }, + .{ 13665021627282055864, 9897834675523659302, 17907668136755296849, 139975126841173266 }, + .{ 9603773719399446181, 10771916301484339398, 10672699855989487527, 137287204938390542 }, + .{ 3630218541553511265, 8139010004241080614, 2876479648932814543, 134650898807055963 }, + .{ 8318835909686377084, 9525369258927993371, 2796120270400437057, 132065217277054270 }, + .{ 11190003059043290163, 12424345635599592110, 12539346395388933763, 129529188211565064 }, + .{ 8701968833973242276, 820569587086330727, 2315591597351480110, 127041858141569228 }, + .{ 5115113890115690487, 16906305245394587826, 9899749468931071388, 124602291907373862 }, + .{ 15543535488939245974, 10945189844466391399, 3553863472349432246, 122209572307020975 }, + .{ 7709257252608325038, 1191832167690640880, 15077137020234258537, 119862799751447719 }, + .{ 7541333244210021737, 9790054727902174575, 5160944773155322014, 117561091926268545 }, + .{ 12297384708782857832, 1281328873123467374, 4827925254630475769, 115303583460052092 }, + .{ 13243237906232367265, 15873887428139547641, 3607993172301799599, 113089425598968120 }, + .{ 11384616453739611114, 15184114243769211033, 13148448124803481057, 110917785887682141 }, + .{ 17727970963596660683, 1196965221832671990, 14537830463956404138, 108787847856377790 }, + .{ 17241367586707330931, 8880584684128262874, 11173506540726547818, 106698810713789254 }, + .{ 7184427196661305643, 14332510582433188173, 14230167953789677901, 104649889046128358 }, +}; + +const POW5_INV_ERRORS: [154]u64 = .{ + 0x1144155514145504, 0x0000541555401141, 0x0000000000000000, 0x0154454000000000, + 0x4114105515544440, 0x0001001111500415, 0x4041411410011000, 0x5550114515155014, + 0x1404100041554551, 0x0515000450404410, 0x5054544401140004, 0x5155501005555105, + 0x1144141000105515, 0x0541500000500000, 0x1104105540444140, 0x4000015055514110, + 0x0054010450004005, 0x4155515404100005, 0x5155145045155555, 0x1511555515440558, + 0x5558544555515555, 0x0000000000000010, 0x5004000000000050, 0x1415510100000010, + 0x4545555444514500, 0x5155151555555551, 0x1441540144044554, 0x5150104045544400, + 0x5450545401444040, 0x5554455045501400, 0x4655155555555145, 0x1000010055455055, + 0x1000004000055004, 0x4455405104000005, 0x4500114504150545, 0x0000000014000000, + 0x5450000000000000, 0x5514551511445555, 0x4111501040555451, 0x4515445500054444, + 0x5101500104100441, 0x1545115155545055, 0x0000000000000000, 0x1554000000100000, + 0x5555545595551555, 0x5555051851455955, 0x5555555555555559, 0x0000400011001555, + 0x0000004400040000, 0x5455511555554554, 0x5614555544115445, 0x6455156145555155, + 0x5455855455415455, 0x5515555144555545, 0x0114400000145155, 0x0000051000450511, + 0x4455154554445100, 0x4554150141544455, 0x65955555559a5965, 0x5555555854559559, + 0x9569654559616595, 0x1040044040005565, 0x1010010500011044, 0x1554015545154540, + 0x4440555401545441, 0x1014441450550105, 0x4545400410504145, 0x5015111541040151, + 0x5145051154000410, 0x1040001044545044, 0x4001400000151410, 0x0540000044040000, + 0x0510555454411544, 0x0400054054141550, 0x1001041145001100, 0x0000000140000000, + 0x0000000014100000, 0x1544005454000140, 0x4050055505445145, 0x0011511104504155, + 0x5505544415045055, 0x1155154445515554, 0x0000000000004555, 0x0000000000000000, + 0x5101010510400004, 0x1514045044440400, 0x5515519555515555, 0x4554545441555545, + 0x1551055955551515, 0x0150000011505515, 0x0044005040400000, 0x0004001004010050, + 0x0000051004450414, 0x0114001101001144, 0x0401000001000001, 0x4500010001000401, + 0x0004100000005000, 0x0105000441101100, 0x0455455550454540, 0x5404050144105505, + 0x4101510540555455, 0x1055541411451555, 0x5451445110115505, 0x1154110010101545, + 0x1145140450054055, 0x5555565415551554, 0x1550559555555555, 0x5555541545045141, + 0x4555455450500100, 0x5510454545554555, 0x1510140115045455, 0x1001050040111510, + 0x5555454555555504, 0x9954155545515554, 0x6596656555555555, 0x0140410051555559, + 0x0011104010001544, 0x965669659a680501, 0x5655a55955556955, 0x4015111014404514, + 0x1414155554505145, 0x0540040011051404, 0x1010000000015005, 0x0010054050004410, + 0x5041104014000100, 0x4440010500100001, 0x1155510504545554, 0x0450151545115541, + 0x4000100400110440, 0x1004440010514440, 0x0000115050450000, 0x0545404455541500, + 0x1051051555505101, 0x5505144554544144, 0x4550545555515550, 0x0015400450045445, + 0x4514155400554415, 0x4555055051050151, 0x1511441450001014, 0x4544554510404414, + 0x4115115545545450, 0x5500541555551555, 0x5550010544155015, 0x0144414045545500, + 0x4154050001050150, 0x5550511111000145, 0x1114504055000151, 0x5104041101451040, + 0x0010501401051441, 0x0010501450504401, 0x4554585440044444, 0x5155555951450455, + 0x0040000400105555, 0x0000000000000001, +}; + +// zig fmt: on