authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-11 18:46:26-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-03-11 18:46:26-07:00
logbd24e66379612a34313206380df1999afcbe95b8
treedad21a82877a71f85b1e686582f3870c351912f1
parent0c61466771ff205a955f3e5002d2a7f2449ccc78
parentbb1fe112f1ddccf0f6f1b71c2dfb2f796645fa94
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19229 from tiehuis/ryu-128

std.fmt: add ryu floating-point formatting implementation

10 files changed, 1198 insertions(+), 2494 deletions(-)

CMakeLists.txt+1-3
......@@ -235,9 +235,7 @@ set(ZIG_STAGE2_SOURCES
235235 "${CMAKE_SOURCE_DIR}/lib/std/elf.zig"
236236 "${CMAKE_SOURCE_DIR}/lib/std/fifo.zig"
237237 "${CMAKE_SOURCE_DIR}/lib/std/fmt.zig"
238 "${CMAKE_SOURCE_DIR}/lib/std/fmt/errol.zig"
239 "${CMAKE_SOURCE_DIR}/lib/std/fmt/errol/enum3.zig"
240 "${CMAKE_SOURCE_DIR}/lib/std/fmt/errol/lookup.zig"
238 "${CMAKE_SOURCE_DIR}/lib/std/fmt/ryu128.zig"
241239 "${CMAKE_SOURCE_DIR}/lib/std/fmt/parse_float.zig"
242240 "${CMAKE_SOURCE_DIR}/lib/std/fs.zig"
243241 "${CMAKE_SOURCE_DIR}/lib/std/fs/AtomicFile.zig"
lib/std/fmt.zig+53-282
......@@ -9,7 +9,7 @@ const assert = std.debug.assert;
99const mem = std.mem;
1010const unicode = std.unicode;
1111const meta = std.meta;
12const errol = @import("fmt/errol.zig");
12const ryu128 = @import("fmt/ryu128.zig");
1313const lossyCast = std.math.lossyCast;
1414const expectFmt = std.testing.expectFmt;
1515
......@@ -763,27 +763,31 @@ fn formatFloatValue(
763763 options: FormatOptions,
764764 writer: anytype,
765765) !void {
766 // this buffer should be enough to display all decimal places of a decimal f64 number.
767 var buf: [512]u8 = undefined;
768 var buf_stream = std.io.fixedBufferStream(&buf);
766 var buf: [ryu128.bufferSize(.decimal, f64)]u8 = undefined;
769767
770768 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
771 formatFloatScientific(value, options, buf_stream.writer()) catch |err| switch (err) {
772 error.NoSpaceLeft => unreachable,
769 const s = ryu128.format(&buf, value, .{ .mode = .scientific, .precision = options.precision }) catch |err| switch (err) {
770 error.BufferTooSmall => "(float)",
773771 };
772 return formatBuf(s, options, writer);
774773 } else if (comptime std.mem.eql(u8, fmt, "d")) {
775 formatFloatDecimal(value, options, buf_stream.writer()) catch |err| switch (err) {
776 error.NoSpaceLeft => unreachable,
774 const s = ryu128.format(&buf, value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) {
775 error.BufferTooSmall => "(float)",
777776 };
777 return formatBuf(s, options, writer);
778778 } else if (comptime std.mem.eql(u8, fmt, "x")) {
779 var buf_stream = std.io.fixedBufferStream(&buf);
779780 formatFloatHexadecimal(value, options, buf_stream.writer()) catch |err| switch (err) {
780781 error.NoSpaceLeft => unreachable,
781782 };
783 return formatBuf(buf_stream.getWritten(), options, writer);
782784 } else {
783785 invalidFmtError(fmt, value);
784786 }
787}
785788
786 return formatBuf(buf_stream.getWritten(), options, writer);
789test {
790 _ = &ryu128;
787791}
788792
789793pub const Case = enum { lower, upper };
......@@ -886,8 +890,7 @@ fn formatSizeImpl(comptime base: comptime_int) type {
886890 return formatBuf("0B", options, writer);
887891 }
888892 // The worst case in terms of space needed is 32 bytes + 3 for the suffix.
889 var buf: [35]u8 = undefined;
890 var bufstream = io.fixedBufferStream(buf[0..]);
893 var buf: [ryu128.min_buffer_size + 3]u8 = undefined;
891894
892895 const mags_si = " kMGTPEZY";
893896 const mags_iec = " KMGTPEZY";
......@@ -905,20 +908,27 @@ fn formatSizeImpl(comptime base: comptime_int) type {
905908 else => unreachable,
906909 };
907910
908 formatFloatDecimal(new_value, options, bufstream.writer()) catch |err| switch (err) {
909 error.NoSpaceLeft => unreachable, // 35 bytes should be enough
911 const s = ryu128.format(&buf, new_value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) {
912 error.BufferTooSmall => unreachable,
910913 };
911914
912 bufstream.writer().writeAll(if (suffix == ' ')
913 "B"
914 else switch (base) {
915 1000 => &[_]u8{ suffix, 'B' },
916 1024 => &[_]u8{ suffix, 'i', 'B' },
915 var i: usize = s.len;
916 if (suffix == ' ') {
917 buf[i] = 'B';
918 i += 1;
919 } else switch (base) {
920 1000 => {
921 buf[i..][0..2].* = [_]u8{ suffix, 'B' };
922 i += 2;
923 },
924 1024 => {
925 buf[i..][0..3].* = [_]u8{ suffix, 'i', 'B' };
926 i += 3;
927 },
917928 else => unreachable,
918 }) catch |err| switch (err) {
919 error.NoSpaceLeft => unreachable,
920 };
921 return formatBuf(bufstream.getWritten(), options, writer);
929 }
930
931 return formatBuf(buf[0..i], options, writer);
922932 }
923933 };
924934}
......@@ -1028,102 +1038,6 @@ pub fn formatBuf(
10281038 }
10291039}
10301040
1031/// Print a float in scientific notation to the specified precision. Null uses full precision.
1032/// For floats with less than 64 bits, it should be the case that every full precision, printed
1033/// value can be re-parsed back to the same type unambiguously.
1034///
1035/// Floats with more than 64 are currently rounded, see https://github.com/ziglang/zig/issues/1181
1036pub fn formatFloatScientific(
1037 value: anytype,
1038 options: FormatOptions,
1039 writer: anytype,
1040) !void {
1041 var x = @as(f64, @floatCast(value));
1042
1043 // Errol doesn't handle these special cases.
1044 if (math.signbit(x)) {
1045 try writer.writeAll("-");
1046 x = -x;
1047 }
1048
1049 if (math.isNan(x)) {
1050 return writer.writeAll("nan");
1051 }
1052 if (math.isPositiveInf(x)) {
1053 return writer.writeAll("inf");
1054 }
1055 if (x == 0.0) {
1056 try writer.writeAll("0");
1057
1058 if (options.precision) |precision| {
1059 if (precision != 0) {
1060 try writer.writeAll(".");
1061 var i: usize = 0;
1062 while (i < precision) : (i += 1) {
1063 try writer.writeAll("0");
1064 }
1065 }
1066 } else {
1067 try writer.writeAll(".0");
1068 }
1069
1070 try writer.writeAll("e+00");
1071 return;
1072 }
1073
1074 var buffer: [32]u8 = undefined;
1075 var float_decimal = errol.errol3(x, buffer[0..]);
1076
1077 if (options.precision) |precision| {
1078 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Scientific);
1079
1080 try writer.writeAll(float_decimal.digits[0..1]);
1081
1082 // {e0} case prints no `.`
1083 if (precision != 0) {
1084 try writer.writeAll(".");
1085
1086 var printed: usize = 0;
1087 if (float_decimal.digits.len > 1) {
1088 const num_digits = @min(float_decimal.digits.len, precision + 1);
1089 try writer.writeAll(float_decimal.digits[1..num_digits]);
1090 printed += num_digits - 1;
1091 }
1092
1093 while (printed < precision) : (printed += 1) {
1094 try writer.writeAll("0");
1095 }
1096 }
1097 } else {
1098 try writer.writeAll(float_decimal.digits[0..1]);
1099 try writer.writeAll(".");
1100 if (float_decimal.digits.len > 1) {
1101 const num_digits = if (@TypeOf(value) == f32) @min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
1102
1103 try writer.writeAll(float_decimal.digits[1..num_digits]);
1104 } else {
1105 try writer.writeAll("0");
1106 }
1107 }
1108
1109 try writer.writeAll("e");
1110 const exp = float_decimal.exp - 1;
1111
1112 if (exp >= 0) {
1113 try writer.writeAll("+");
1114 if (exp > -10 and exp < 10) {
1115 try writer.writeAll("0");
1116 }
1117 try formatInt(exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
1118 } else {
1119 try writer.writeAll("-");
1120 if (exp > -10 and exp < 10) {
1121 try writer.writeAll("0");
1122 }
1123 try formatInt(-exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
1124 }
1125}
1126
11271041pub fn formatFloatHexadecimal(
11281042 value: anytype,
11291043 options: FormatOptions,
......@@ -1233,149 +1147,6 @@ pub fn formatFloatHexadecimal(
12331147 try formatInt(exponent - exponent_bias, 10, .lower, .{}, writer);
12341148}
12351149
1236/// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
1237/// By default floats are printed at full precision (no rounding).
1238///
1239/// Floats with more than 64 bits are not yet supported, see https://github.com/ziglang/zig/issues/1181
1240pub fn formatFloatDecimal(
1241 value: anytype,
1242 options: FormatOptions,
1243 writer: anytype,
1244) !void {
1245 var x = @as(f64, value);
1246
1247 // Errol doesn't handle these special cases.
1248 if (math.signbit(x)) {
1249 try writer.writeAll("-");
1250 x = -x;
1251 }
1252
1253 if (math.isNan(x)) {
1254 return writer.writeAll("nan");
1255 }
1256 if (math.isPositiveInf(x)) {
1257 return writer.writeAll("inf");
1258 }
1259 if (x == 0.0) {
1260 try writer.writeAll("0");
1261
1262 if (options.precision) |precision| {
1263 if (precision != 0) {
1264 try writer.writeAll(".");
1265 var i: usize = 0;
1266 while (i < precision) : (i += 1) {
1267 try writer.writeAll("0");
1268 }
1269 }
1270 }
1271
1272 return;
1273 }
1274
1275 // non-special case, use errol3
1276 var buffer: [32]u8 = undefined;
1277 var float_decimal = errol.errol3(x, buffer[0..]);
1278
1279 if (options.precision) |precision| {
1280 errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Decimal);
1281
1282 // exp < 0 means the leading is always 0 as errol result is normalized.
1283 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1284
1285 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1286 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1287
1288 if (num_digits_whole > 0) {
1289 // We may have to zero pad, for instance 1e4 requires zero padding.
1290 try writer.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]);
1291
1292 var i: usize = num_digits_whole_no_pad;
1293 while (i < num_digits_whole) : (i += 1) {
1294 try writer.writeAll("0");
1295 }
1296 } else {
1297 try writer.writeAll("0");
1298 }
1299
1300 // {.0} special case doesn't want a trailing '.'
1301 if (precision == 0) {
1302 return;
1303 }
1304
1305 try writer.writeAll(".");
1306
1307 // Keep track of fractional count printed for case where we pre-pad then post-pad with 0's.
1308 var printed: usize = 0;
1309
1310 // Zero-fill until we reach significant digits or run out of precision.
1311 if (float_decimal.exp <= 0) {
1312 const zero_digit_count = @as(usize, @intCast(-float_decimal.exp));
1313 const zeros_to_print = @min(zero_digit_count, precision);
1314
1315 var i: usize = 0;
1316 while (i < zeros_to_print) : (i += 1) {
1317 try writer.writeAll("0");
1318 printed += 1;
1319 }
1320
1321 if (printed >= precision) {
1322 return;
1323 }
1324 }
1325
1326 // Remaining fractional portion, zero-padding if insufficient.
1327 assert(precision >= printed);
1328 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
1329 try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
1330 return;
1331 } else {
1332 try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad..]);
1333 printed += float_decimal.digits.len - num_digits_whole_no_pad;
1334
1335 while (printed < precision) : (printed += 1) {
1336 try writer.writeAll("0");
1337 }
1338 }
1339 } else {
1340 // exp < 0 means the leading is always 0 as errol result is normalized.
1341 const num_digits_whole = if (float_decimal.exp > 0) @as(usize, @intCast(float_decimal.exp)) else 0;
1342
1343 // the actual slice into the buffer, we may need to zero-pad between num_digits_whole and this.
1344 const num_digits_whole_no_pad = @min(num_digits_whole, float_decimal.digits.len);
1345
1346 if (num_digits_whole > 0) {
1347 // We may have to zero pad, for instance 1e4 requires zero padding.
1348 try writer.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]);
1349
1350 var i: usize = num_digits_whole_no_pad;
1351 while (i < num_digits_whole) : (i += 1) {
1352 try writer.writeAll("0");
1353 }
1354 } else {
1355 try writer.writeAll("0");
1356 }
1357
1358 // Omit `.` if no fractional portion
1359 if (float_decimal.exp >= 0 and num_digits_whole_no_pad == float_decimal.digits.len) {
1360 return;
1361 }
1362
1363 try writer.writeAll(".");
1364
1365 // Zero-fill until we reach significant digits or run out of precision.
1366 if (float_decimal.exp < 0) {
1367 const zero_digit_count = @as(usize, @intCast(-float_decimal.exp));
1368
1369 var i: usize = 0;
1370 while (i < zero_digit_count) : (i += 1) {
1371 try writer.writeAll("0");
1372 }
1373 }
1374
1375 try writer.writeAll(float_decimal.digits[num_digits_whole_no_pad..]);
1376 }
1377}
1378
13791150pub fn formatInt(
13801151 value: anytype,
13811152 base: u8,
......@@ -1451,7 +1222,7 @@ pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options
14511222}
14521223
14531224// Converts values in the range [0, 100) to a string.
1454fn digits2(value: usize) [2]u8 {
1225pub fn digits2(value: usize) [2]u8 {
14551226 return ("0001020304050607080910111213141516171819" ++
14561227 "2021222324252627282930313233343536373839" ++
14571228 "4041424344454647484950515253545556575859" ++
......@@ -2362,7 +2133,7 @@ test "struct" {
23622133 // Tuples
23632134 try expectFmt("{ }", "{}", .{.{}});
23642135 try expectFmt("{ -1 }", "{}", .{.{-1}});
2365 try expectFmt("{ -1, 42, 2.5e+04 }", "{}", .{.{ -1, 42, 0.25e5 }});
2136 try expectFmt("{ -1, 42, 2.5e4 }", "{}", .{.{ -1, 42, 0.25e5 }});
23662137}
23672138
23682139test "enum" {
......@@ -2409,19 +2180,19 @@ test "non-exhaustive enum" {
24092180}
24102181
24112182test "float.scientific" {
2412 try expectFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)});
2413 try expectFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)});
2414 try expectFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)});
2183 try expectFmt("f32: 1.34e0", "f32: {e}", .{@as(f32, 1.34)});
2184 try expectFmt("f32: 1.234e1", "f32: {e}", .{@as(f32, 12.34)});
2185 try expectFmt("f64: -1.234e11", "f64: {e}", .{@as(f64, -12.34e10)});
24152186 try expectFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)});
24162187}
24172188
24182189test "float.scientific.precision" {
24192190 try expectFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});
2420 try expectFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 814313563))))});
2421 try expectFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1006632960))))});
2422 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
2191 try expectFmt("f64: 1.00000e-9", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 814313563))))});
2192 try expectFmt("f64: 7.81250e-3", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1006632960))))});
2193 // libc rounds 1.000005e5 to 1.00000e5 but zig does 1.00001e5.
24232194 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
2424 try expectFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1203982400))))});
2195 try expectFmt("f64: 1.00001e5", "f64: {e:.5}", .{@as(f64, @as(f32, @bitCast(@as(u32, 1203982400))))});
24252196}
24262197
24272198test "float.special" {
......@@ -2490,7 +2261,7 @@ test "float.hexadecimal.precision" {
24902261}
24912262
24922263test "float.decimal" {
2493 try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
2264 try expectFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e29)});
24942265 try expectFmt("f32: 0", "f32: {d}", .{@as(f32, 0.0)});
24952266 try expectFmt("f32: 0", "f32: {d:.0}", .{@as(f32, 0.0)});
24962267 try expectFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
......@@ -2703,10 +2474,10 @@ test "formatFloatValue with comptime_float" {
27032474 var buf: [20]u8 = undefined;
27042475 var fbs = std.io.fixedBufferStream(&buf);
27052476 try formatFloatValue(value, "", FormatOptions{}, fbs.writer());
2706 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00"));
2477 try std.testing.expectEqualStrings(fbs.getWritten(), "1e0");
27072478
2708 try expectFmt("1.0e+00", "{}", .{value});
2709 try expectFmt("1.0e+00", "{}", .{1.0});
2479 try expectFmt("1e0", "{}", .{value});
2480 try expectFmt("1e0", "{}", .{1.0});
27102481}
27112482
27122483test "formatType max_depth" {
......@@ -2843,16 +2614,16 @@ test "padding fill char utf" {
28432614
28442615test "decimal float padding" {
28452616 const number: f32 = 3.1415;
2846 try expectFmt("left-pad: **3.141\n", "left-pad: {d:*>7.3}\n", .{number});
2847 try expectFmt("center-pad: *3.141*\n", "center-pad: {d:*^7.3}\n", .{number});
2848 try expectFmt("right-pad: 3.141**\n", "right-pad: {d:*<7.3}\n", .{number});
2617 try expectFmt("left-pad: **3.142\n", "left-pad: {d:*>7.3}\n", .{number});
2618 try expectFmt("center-pad: *3.142*\n", "center-pad: {d:*^7.3}\n", .{number});
2619 try expectFmt("right-pad: 3.142**\n", "right-pad: {d:*<7.3}\n", .{number});
28492620}
28502621
28512622test "sci float padding" {
28522623 const number: f32 = 3.1415;
2853 try expectFmt("left-pad: **3.141e+00\n", "left-pad: {e:*>11.3}\n", .{number});
2854 try expectFmt("center-pad: *3.141e+00*\n", "center-pad: {e:*^11.3}\n", .{number});
2855 try expectFmt("right-pad: 3.141e+00**\n", "right-pad: {e:*<11.3}\n", .{number});
2624 try expectFmt("left-pad: ****3.142e0\n", "left-pad: {e:*>11.3}\n", .{number});
2625 try expectFmt("center-pad: **3.142e0**\n", "center-pad: {e:*^11.3}\n", .{number});
2626 try expectFmt("right-pad: 3.142e0****\n", "right-pad: {e:*<11.3}\n", .{number});
28562627}
28572628
28582629test "null" {
......@@ -2883,8 +2654,8 @@ test "runtime width specifier" {
28832654test "runtime precision specifier" {
28842655 const number: f32 = 3.1415;
28852656 const precision: usize = 2;
2886 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });
2887 try expectFmt("3.14e+00", "{:1.[precision]}", .{ .number = number, .precision = precision });
2657 try expectFmt("3.14e0", "{:1.[1]}", .{ number, precision });
2658 try expectFmt("3.14e0", "{:1.[precision]}", .{ .number = number, .precision = precision });
28882659}
28892660
28902661test "recursive format function" {
lib/std/fmt/errol.zig deleted-709
......@@ -1,709 +0,0 @@
1const std = @import("../std.zig");
2const enum3 = @import("errol/enum3.zig").enum3;
3const enum3_data = @import("errol/enum3.zig").enum3_data;
4const lookup_table = @import("errol/lookup.zig").lookup_table;
5const HP = @import("errol/lookup.zig").HP;
6const math = std.math;
7const mem = std.mem;
8const assert = std.debug.assert;
9
10pub const FloatDecimal = struct {
11 digits: []u8,
12 exp: i32,
13};
14
15pub const RoundMode = enum {
16 // Round only the fractional portion (e.g. 1234.23 has precision 2)
17 Decimal,
18 // Round the entire whole/fractional portion (e.g. 1.23423e3 has precision 5)
19 Scientific,
20};
21
22/// Round a FloatDecimal as returned by errol3 to the specified fractional precision.
23/// All digits after the specified precision should be considered invalid.
24pub fn roundToPrecision(float_decimal: *FloatDecimal, precision: usize, mode: RoundMode) void {
25 // The round digit refers to the index which we should look at to determine
26 // whether we need to round to match the specified precision.
27 var round_digit: usize = 0;
28
29 switch (mode) {
30 RoundMode.Decimal => {
31 if (float_decimal.exp >= 0) {
32 round_digit = precision + @as(usize, @intCast(float_decimal.exp));
33 } else {
34 // if a small negative exp, then adjust we need to offset by the number
35 // of leading zeros that will occur.
36 const min_exp_required = @as(usize, @intCast(-float_decimal.exp));
37 if (precision > min_exp_required) {
38 round_digit = precision - min_exp_required;
39 }
40 }
41 },
42 RoundMode.Scientific => {
43 round_digit = 1 + precision;
44 },
45 }
46
47 // It suffices to look at just this digit. We don't round and propagate say 0.04999 to 0.05
48 // first, and then to 0.1 in the case of a {.1} single precision.
49
50 // Find the digit which will signify the round point and start rounding backwards.
51 if (round_digit < float_decimal.digits.len and float_decimal.digits[round_digit] - '0' >= 5) {
52 assert(round_digit >= 0);
53
54 var i = round_digit;
55 while (true) {
56 if (i == 0) {
57 // Rounded all the way past the start. This was of the form 9.999...
58 // Slot the new digit in place and increase the exponent.
59 float_decimal.exp += 1;
60
61 // Re-size the buffer to use the reserved leading byte.
62 const one_before = @as([*]u8, @ptrFromInt(@intFromPtr(&float_decimal.digits[0]) - 1));
63 float_decimal.digits = one_before[0 .. float_decimal.digits.len + 1];
64 float_decimal.digits[0] = '1';
65 return;
66 }
67
68 i -= 1;
69
70 const new_value = (float_decimal.digits[i] - '0' + 1) % 10;
71 float_decimal.digits[i] = new_value + '0';
72
73 // must continue rounding until non-9
74 if (new_value != 0) {
75 return;
76 }
77 }
78 }
79}
80
81/// Corrected Errol3 double to ASCII conversion.
82pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
83 const bits = @as(u64, @bitCast(value));
84 const i = tableLowerBound(bits);
85 if (i < enum3.len and enum3[i] == bits) {
86 const data = enum3_data[i];
87 const digits = buffer[1..][0..data.str.len];
88 @memcpy(digits, data.str);
89 return FloatDecimal{
90 .digits = digits,
91 .exp = data.exp,
92 };
93 }
94
95 // We generate digits starting at index 1. If rounding a buffer later then it may be
96 // required to generate a preceding digit in some cases (9.999) in which case we use
97 // the 0-index for this extra digit.
98 return errol3u(value, buffer[1..]);
99}
100
101/// Uncorrected Errol3 double to ASCII conversion.
102fn errol3u(val: f64, buffer: []u8) FloatDecimal {
103 // check if in integer or fixed range
104 if (val > 9.007199254740992e15 and val < 3.40282366920938e+38) {
105 return errolInt(val, buffer);
106 } else if (val >= 16.0 and val < 9.007199254740992e15) {
107 return errolFixed(val, buffer);
108 }
109 return errolSlow(val, buffer);
110}
111
112fn errolSlow(val: f64, buffer: []u8) FloatDecimal {
113 // normalize the midpoint
114
115 const e = math.frexp(val).exponent;
116 var exp = @as(i16, @intFromFloat(@floor(307 + @as(f64, @floatFromInt(e)) * 0.30103)));
117 if (exp < 20) {
118 exp = 20;
119 } else if (@as(usize, @intCast(exp)) >= lookup_table.len) {
120 exp = @as(i16, @intCast(lookup_table.len - 1));
121 }
122
123 var mid = lookup_table[@as(usize, @intCast(exp))];
124 mid = hpProd(mid, val);
125 const lten = lookup_table[@as(usize, @intCast(exp))].val;
126
127 exp -= 307;
128
129 var ten: f64 = 1.0;
130
131 while (mid.val > 10.0 or (mid.val == 10.0 and mid.off >= 0.0)) {
132 exp += 1;
133 hpDiv10(&mid);
134 ten /= 10.0;
135 }
136
137 while (mid.val < 1.0 or (mid.val == 1.0 and mid.off < 0.0)) {
138 exp -= 1;
139 hpMul10(&mid);
140 ten *= 10.0;
141 }
142
143 // compute boundaries
144 var high = HP{
145 .val = mid.val,
146 .off = mid.off + (fpnext(val) - val) * lten * ten / 2.0,
147 };
148 var low = HP{
149 .val = mid.val,
150 .off = mid.off + (fpprev(val) - val) * lten * ten / 2.0,
151 };
152
153 hpNormalize(&high);
154 hpNormalize(&low);
155
156 // normalized boundaries
157
158 while (high.val > 10.0 or (high.val == 10.0 and high.off >= 0.0)) {
159 exp += 1;
160 hpDiv10(&high);
161 hpDiv10(&low);
162 }
163
164 while (high.val < 1.0 or (high.val == 1.0 and high.off < 0.0)) {
165 exp -= 1;
166 hpMul10(&high);
167 hpMul10(&low);
168 }
169
170 // digit generation
171 var buf_index: usize = 0;
172 const bound = buffer.len - 1;
173 while (buf_index < bound) {
174 var hdig = @as(u8, @intFromFloat(@floor(high.val)));
175 if ((high.val == @as(f64, @floatFromInt(hdig))) and (high.off < 0)) hdig -= 1;
176
177 var ldig = @as(u8, @intFromFloat(@floor(low.val)));
178 if ((low.val == @as(f64, @floatFromInt(ldig))) and (low.off < 0)) ldig -= 1;
179
180 if (ldig != hdig) break;
181
182 buffer[buf_index] = hdig + '0';
183 buf_index += 1;
184 high.val -= @as(f64, @floatFromInt(hdig));
185 low.val -= @as(f64, @floatFromInt(ldig));
186 hpMul10(&high);
187 hpMul10(&low);
188 }
189
190 const tmp = (high.val + low.val) / 2.0;
191 var mdig = @as(u8, @intFromFloat(@floor(tmp + 0.5)));
192 if ((@as(f64, @floatFromInt(mdig)) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
193
194 buffer[buf_index] = mdig + '0';
195 buf_index += 1;
196
197 return FloatDecimal{
198 .digits = buffer[0..buf_index],
199 .exp = exp,
200 };
201}
202
203fn tableLowerBound(k: u64) usize {
204 var i = enum3.len;
205 var j: usize = 0;
206
207 while (j < enum3.len) {
208 if (enum3[j] < k) {
209 j = 2 * j + 2;
210 } else {
211 i = j;
212 j = 2 * j + 1;
213 }
214 }
215
216 return i;
217}
218
219/// Compute the product of an HP number and a double.
220/// @in: The HP number.
221/// @val: The double.
222/// &returns: The HP number.
223fn hpProd(in: HP, val: f64) HP {
224 var hi: f64 = undefined;
225 var lo: f64 = undefined;
226 split(in.val, &hi, &lo);
227
228 var hi2: f64 = undefined;
229 var lo2: f64 = undefined;
230 split(val, &hi2, &lo2);
231
232 const p = in.val * val;
233 const e = ((hi * hi2 - p) + lo * hi2 + hi * lo2) + lo * lo2;
234
235 return HP{
236 .val = p,
237 .off = in.off * val + e,
238 };
239}
240
241/// Split a double into two halves.
242/// @val: The double.
243/// @hi: The high bits.
244/// @lo: The low bits.
245fn split(val: f64, hi: *f64, lo: *f64) void {
246 hi.* = gethi(val);
247 lo.* = val - hi.*;
248}
249
250fn gethi(in: f64) f64 {
251 const bits = @as(u64, @bitCast(in));
252 const new_bits = bits & 0xFFFFFFFFF8000000;
253 return @as(f64, @bitCast(new_bits));
254}
255
256/// Normalize the number by factoring in the error.
257/// @hp: The float pair.
258fn hpNormalize(hp: *HP) void {
259 const val = hp.val;
260 hp.val += hp.off;
261 hp.off += val - hp.val;
262}
263
264/// Divide the high-precision number by ten.
265/// @hp: The high-precision number
266fn hpDiv10(hp: *HP) void {
267 var val = hp.val;
268
269 hp.val /= 10.0;
270 hp.off /= 10.0;
271
272 val -= hp.val * 8.0;
273 val -= hp.val * 2.0;
274
275 hp.off += val / 10.0;
276
277 hpNormalize(hp);
278}
279
280/// Multiply the high-precision number by ten.
281/// @hp: The high-precision number
282fn hpMul10(hp: *HP) void {
283 const val = hp.val;
284
285 hp.val *= 10.0;
286 hp.off *= 10.0;
287
288 var off = hp.val;
289 off -= val * 8.0;
290 off -= val * 2.0;
291
292 hp.off -= off;
293
294 hpNormalize(hp);
295}
296
297/// Integer conversion algorithm, guaranteed correct, optimal, and best.
298/// @val: The val.
299/// @buf: The output buffer.
300/// &return: The exponent.
301fn errolInt(val: f64, buffer: []u8) FloatDecimal {
302 const pow19 = @as(u128, 1e19);
303
304 assert((val > 9.007199254740992e15) and val < (3.40282366920938e38));
305
306 var mid = @as(u128, @intFromFloat(val));
307 var low: u128 = mid - fpeint((fpnext(val) - val) / 2.0);
308 var high: u128 = mid + fpeint((val - fpprev(val)) / 2.0);
309
310 if (@as(u64, @bitCast(val)) & 0x1 != 0) {
311 high -= 1;
312 } else {
313 low -= 1;
314 }
315
316 var l64 = @as(u64, @intCast(low % pow19));
317 const lf = @as(u64, @intCast((low / pow19) % pow19));
318
319 var h64 = @as(u64, @intCast(high % pow19));
320 const hf = @as(u64, @intCast((high / pow19) % pow19));
321
322 if (lf != hf) {
323 l64 = lf;
324 h64 = hf;
325 mid = mid / (pow19 / 10);
326 }
327
328 var mi: i32 = mismatch10(l64, h64);
329 var x: u64 = 1;
330 {
331 var i: i32 = @intFromBool(lf == hf);
332 while (i < mi) : (i += 1) {
333 x *= 10;
334 }
335 }
336 const m64 = @as(u64, @truncate(@divTrunc(mid, x)));
337
338 if (lf != hf) mi += 19;
339
340 var buf_index = u64toa(m64, buffer) - 1;
341
342 if (mi != 0) {
343 const round_up = buffer[buf_index] >= '5';
344 if (buf_index == 0 or (round_up and buffer[buf_index - 1] == '9')) return errolSlow(val, buffer);
345 buffer[buf_index - 1] += @intFromBool(round_up);
346 } else {
347 buf_index += 1;
348 }
349
350 return FloatDecimal{
351 .digits = buffer[0..buf_index],
352 .exp = @as(i32, @intCast(buf_index)) + mi,
353 };
354}
355
356/// Fixed point conversion algorithm, guaranteed correct, optimal, and best.
357/// @val: The val.
358/// @buf: The output buffer.
359/// &return: The exponent.
360fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
361 assert((val >= 16.0) and (val < 9.007199254740992e15));
362
363 const u = @as(u64, @intFromFloat(val));
364 const n = @as(f64, @floatFromInt(u));
365
366 var mid = val - n;
367 var lo = ((fpprev(val) - n) + mid) / 2.0;
368 var hi = ((fpnext(val) - n) + mid) / 2.0;
369
370 const buf_index = u64toa(u, buffer);
371 const exp: i32 = @intCast(buf_index);
372 var j = buf_index;
373 buffer[j] = 0;
374
375 if (mid != 0.0) {
376 while (mid != 0.0) {
377 lo *= 10.0;
378 const ldig = @as(i32, @intFromFloat(lo));
379 lo -= @as(f64, @floatFromInt(ldig));
380
381 mid *= 10.0;
382 const mdig = @as(i32, @intFromFloat(mid));
383 mid -= @as(f64, @floatFromInt(mdig));
384
385 hi *= 10.0;
386 const hdig = @as(i32, @intFromFloat(hi));
387 hi -= @as(f64, @floatFromInt(hdig));
388
389 buffer[j] = @as(u8, @intCast(mdig + '0'));
390 j += 1;
391
392 if (hdig != ldig or j > 50) break;
393 }
394
395 if (mid > 0.5) {
396 buffer[j - 1] += 1;
397 } else if ((mid == 0.5) and (buffer[j - 1] & 0x1) != 0) {
398 buffer[j - 1] += 1;
399 }
400 } else {
401 while (buffer[j - 1] == '0') {
402 buffer[j - 1] = 0;
403 j -= 1;
404 }
405 }
406
407 buffer[j] = 0;
408
409 return FloatDecimal{
410 .digits = buffer[0..j],
411 .exp = exp,
412 };
413}
414
415fn fpnext(val: f64) f64 {
416 return @as(f64, @bitCast(@as(u64, @bitCast(val)) +% 1));
417}
418
419fn fpprev(val: f64) f64 {
420 return @as(f64, @bitCast(@as(u64, @bitCast(val)) -% 1));
421}
422
423pub const c_digits_lut = [_]u8{
424 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6',
425 '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3',
426 '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0',
427 '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7',
428 '2', '8', '2', '9', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4',
429 '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '4', '0', '4', '1',
430 '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8',
431 '4', '9', '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5',
432 '5', '6', '5', '7', '5', '8', '5', '9', '6', '0', '6', '1', '6', '2',
433 '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
434 '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6',
435 '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', '2', '8', '3',
436 '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '9', '0',
437 '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7',
438 '9', '8', '9', '9',
439};
440
441fn u64toa(value_param: u64, buffer: []u8) usize {
442 var value = value_param;
443 const kTen8: u64 = 100000000;
444 const kTen9: u64 = kTen8 * 10;
445 const kTen10: u64 = kTen8 * 100;
446 const kTen11: u64 = kTen8 * 1000;
447 const kTen12: u64 = kTen8 * 10000;
448 const kTen13: u64 = kTen8 * 100000;
449 const kTen14: u64 = kTen8 * 1000000;
450 const kTen15: u64 = kTen8 * 10000000;
451 const kTen16: u64 = kTen8 * kTen8;
452
453 var buf_index: usize = 0;
454
455 if (value < kTen8) {
456 const v = @as(u32, @intCast(value));
457 if (v < 10000) {
458 const d1: u32 = (v / 100) << 1;
459 const d2: u32 = (v % 100) << 1;
460
461 if (v >= 1000) {
462 buffer[buf_index] = c_digits_lut[d1];
463 buf_index += 1;
464 }
465 if (v >= 100) {
466 buffer[buf_index] = c_digits_lut[d1 + 1];
467 buf_index += 1;
468 }
469 if (v >= 10) {
470 buffer[buf_index] = c_digits_lut[d2];
471 buf_index += 1;
472 }
473 buffer[buf_index] = c_digits_lut[d2 + 1];
474 buf_index += 1;
475 } else {
476 // value = bbbbcccc
477 const b: u32 = v / 10000;
478 const c: u32 = v % 10000;
479
480 const d1: u32 = (b / 100) << 1;
481 const d2: u32 = (b % 100) << 1;
482
483 const d3: u32 = (c / 100) << 1;
484 const d4: u32 = (c % 100) << 1;
485
486 if (value >= 10000000) {
487 buffer[buf_index] = c_digits_lut[d1];
488 buf_index += 1;
489 }
490 if (value >= 1000000) {
491 buffer[buf_index] = c_digits_lut[d1 + 1];
492 buf_index += 1;
493 }
494 if (value >= 100000) {
495 buffer[buf_index] = c_digits_lut[d2];
496 buf_index += 1;
497 }
498 buffer[buf_index] = c_digits_lut[d2 + 1];
499 buf_index += 1;
500
501 buffer[buf_index] = c_digits_lut[d3];
502 buf_index += 1;
503 buffer[buf_index] = c_digits_lut[d3 + 1];
504 buf_index += 1;
505 buffer[buf_index] = c_digits_lut[d4];
506 buf_index += 1;
507 buffer[buf_index] = c_digits_lut[d4 + 1];
508 buf_index += 1;
509 }
510 } else if (value < kTen16) {
511 const v0: u32 = @as(u32, @intCast(value / kTen8));
512 const v1: u32 = @as(u32, @intCast(value % kTen8));
513
514 const b0: u32 = v0 / 10000;
515 const c0: u32 = v0 % 10000;
516
517 const d1: u32 = (b0 / 100) << 1;
518 const d2: u32 = (b0 % 100) << 1;
519
520 const d3: u32 = (c0 / 100) << 1;
521 const d4: u32 = (c0 % 100) << 1;
522
523 const b1: u32 = v1 / 10000;
524 const c1: u32 = v1 % 10000;
525
526 const d5: u32 = (b1 / 100) << 1;
527 const d6: u32 = (b1 % 100) << 1;
528
529 const d7: u32 = (c1 / 100) << 1;
530 const d8: u32 = (c1 % 100) << 1;
531
532 if (value >= kTen15) {
533 buffer[buf_index] = c_digits_lut[d1];
534 buf_index += 1;
535 }
536 if (value >= kTen14) {
537 buffer[buf_index] = c_digits_lut[d1 + 1];
538 buf_index += 1;
539 }
540 if (value >= kTen13) {
541 buffer[buf_index] = c_digits_lut[d2];
542 buf_index += 1;
543 }
544 if (value >= kTen12) {
545 buffer[buf_index] = c_digits_lut[d2 + 1];
546 buf_index += 1;
547 }
548 if (value >= kTen11) {
549 buffer[buf_index] = c_digits_lut[d3];
550 buf_index += 1;
551 }
552 if (value >= kTen10) {
553 buffer[buf_index] = c_digits_lut[d3 + 1];
554 buf_index += 1;
555 }
556 if (value >= kTen9) {
557 buffer[buf_index] = c_digits_lut[d4];
558 buf_index += 1;
559 }
560 if (value >= kTen8) {
561 buffer[buf_index] = c_digits_lut[d4 + 1];
562 buf_index += 1;
563 }
564
565 buffer[buf_index] = c_digits_lut[d5];
566 buf_index += 1;
567 buffer[buf_index] = c_digits_lut[d5 + 1];
568 buf_index += 1;
569 buffer[buf_index] = c_digits_lut[d6];
570 buf_index += 1;
571 buffer[buf_index] = c_digits_lut[d6 + 1];
572 buf_index += 1;
573 buffer[buf_index] = c_digits_lut[d7];
574 buf_index += 1;
575 buffer[buf_index] = c_digits_lut[d7 + 1];
576 buf_index += 1;
577 buffer[buf_index] = c_digits_lut[d8];
578 buf_index += 1;
579 buffer[buf_index] = c_digits_lut[d8 + 1];
580 buf_index += 1;
581 } else {
582 const a = @as(u32, @intCast(value / kTen16)); // 1 to 1844
583 value %= kTen16;
584
585 if (a < 10) {
586 buffer[buf_index] = '0' + @as(u8, @intCast(a));
587 buf_index += 1;
588 } else if (a < 100) {
589 const i: u32 = a << 1;
590 buffer[buf_index] = c_digits_lut[i];
591 buf_index += 1;
592 buffer[buf_index] = c_digits_lut[i + 1];
593 buf_index += 1;
594 } else if (a < 1000) {
595 buffer[buf_index] = '0' + @as(u8, @intCast(a / 100));
596 buf_index += 1;
597
598 const i: u32 = (a % 100) << 1;
599 buffer[buf_index] = c_digits_lut[i];
600 buf_index += 1;
601 buffer[buf_index] = c_digits_lut[i + 1];
602 buf_index += 1;
603 } else {
604 const i: u32 = (a / 100) << 1;
605 const j: u32 = (a % 100) << 1;
606 buffer[buf_index] = c_digits_lut[i];
607 buf_index += 1;
608 buffer[buf_index] = c_digits_lut[i + 1];
609 buf_index += 1;
610 buffer[buf_index] = c_digits_lut[j];
611 buf_index += 1;
612 buffer[buf_index] = c_digits_lut[j + 1];
613 buf_index += 1;
614 }
615
616 const v0 = @as(u32, @intCast(value / kTen8));
617 const v1 = @as(u32, @intCast(value % kTen8));
618
619 const b0: u32 = v0 / 10000;
620 const c0: u32 = v0 % 10000;
621
622 const d1: u32 = (b0 / 100) << 1;
623 const d2: u32 = (b0 % 100) << 1;
624
625 const d3: u32 = (c0 / 100) << 1;
626 const d4: u32 = (c0 % 100) << 1;
627
628 const b1: u32 = v1 / 10000;
629 const c1: u32 = v1 % 10000;
630
631 const d5: u32 = (b1 / 100) << 1;
632 const d6: u32 = (b1 % 100) << 1;
633
634 const d7: u32 = (c1 / 100) << 1;
635 const d8: u32 = (c1 % 100) << 1;
636
637 buffer[buf_index] = c_digits_lut[d1];
638 buf_index += 1;
639 buffer[buf_index] = c_digits_lut[d1 + 1];
640 buf_index += 1;
641 buffer[buf_index] = c_digits_lut[d2];
642 buf_index += 1;
643 buffer[buf_index] = c_digits_lut[d2 + 1];
644 buf_index += 1;
645 buffer[buf_index] = c_digits_lut[d3];
646 buf_index += 1;
647 buffer[buf_index] = c_digits_lut[d3 + 1];
648 buf_index += 1;
649 buffer[buf_index] = c_digits_lut[d4];
650 buf_index += 1;
651 buffer[buf_index] = c_digits_lut[d4 + 1];
652 buf_index += 1;
653 buffer[buf_index] = c_digits_lut[d5];
654 buf_index += 1;
655 buffer[buf_index] = c_digits_lut[d5 + 1];
656 buf_index += 1;
657 buffer[buf_index] = c_digits_lut[d6];
658 buf_index += 1;
659 buffer[buf_index] = c_digits_lut[d6 + 1];
660 buf_index += 1;
661 buffer[buf_index] = c_digits_lut[d7];
662 buf_index += 1;
663 buffer[buf_index] = c_digits_lut[d7 + 1];
664 buf_index += 1;
665 buffer[buf_index] = c_digits_lut[d8];
666 buf_index += 1;
667 buffer[buf_index] = c_digits_lut[d8 + 1];
668 buf_index += 1;
669 }
670
671 return buf_index;
672}
673
674fn fpeint(from: f64) u128 {
675 const bits = @as(u64, @bitCast(from));
676 assert((bits & ((1 << 52) - 1)) == 0);
677
678 return @as(u128, 1) << @as(u7, @truncate((bits >> 52) -% 1023));
679}
680
681/// Given two different integers with the same length in terms of the number
682/// of decimal digits, index the digits from the right-most position starting
683/// from zero, find the first index where the digits in the two integers
684/// divergent starting from the highest index.
685/// @a: Integer a.
686/// @b: Integer b.
687/// &returns: An index within [0, 19).
688fn mismatch10(a: u64, b: u64) i32 {
689 const pow10 = 10000000000;
690 const af = a / pow10;
691 const bf = b / pow10;
692
693 var i: i32 = 0;
694 var a_copy = a;
695 var b_copy = b;
696
697 if (af != bf) {
698 i = 10;
699 a_copy = af;
700 b_copy = bf;
701 }
702
703 while (true) : (i += 1) {
704 a_copy /= 10;
705 b_copy /= 10;
706
707 if (a_copy == b_copy) return i;
708 }
709}
lib/std/fmt/errol/enum3.zig deleted-881
......@@ -1,881 +0,0 @@
1pub const enum3 = [_]u64{
2 0x4e2e2785c3a2a20b,
3 0x240a28877a09a4e1,
4 0x728fca36c06cf106,
5 0x1016b100e18e5c17,
6 0x3159190e30e46c1d,
7 0x64312a13daa46fe4,
8 0x7c41926c7a7122ba,
9 0x08667a3c8dc4bc9c,
10 0x18dde996371c6060,
11 0x297c2c31a31998ae,
12 0x368b870de5d93270,
13 0x57d561def4a9ee32,
14 0x6d275d226331d03a,
15 0x76703d7cb98edc59,
16 0x7ec490abad057752,
17 0x037be9d5a60850b5,
18 0x0c63165633977bca,
19 0x14a048cb468bc209,
20 0x20dc29bc6879dfcd,
21 0x2643dc6227de9148,
22 0x2d64f14348a4c5db,
23 0x341eef5e1f90ac35,
24 0x4931159a8bd8a240,
25 0x503ca9bade45b94a,
26 0x5c1af5b5378aa2e5,
27 0x6b4ef9beaa7aa584,
28 0x6ef1c382c3819a0a,
29 0x754fe46e378bf133,
30 0x7ace779fddf21622,
31 0x7df22815078cb97b,
32 0x7f33c8eeb77b8d05,
33 0x011b7aa3d73f6658,
34 0x06ceb7f2c53db97f,
35 0x0b8f3d82e9356287,
36 0x0e304273b18918b0,
37 0x139fb24e492936f6,
38 0x176090684f5fe997,
39 0x1e3035e7b5183922,
40 0x220ce77c2b3328fc,
41 0x246441ed79830182,
42 0x279b5cd8bbdd8770,
43 0x2cc7c3fba45c1272,
44 0x3081eab25ad0fcf7,
45 0x329f5a18504dfaac,
46 0x347eef5e1f90ac35,
47 0x3a978cfcab31064c,
48 0x4baa32ac316fb3ab,
49 0x4eb9a2c2a34ac2f9,
50 0x522f6a5025e71a61,
51 0x5935ede8cce30845,
52 0x5f9aeac2d1ea2695,
53 0x6820ee7811241ad3,
54 0x6c06c9e14b7c22c3,
55 0x6e5a2fbffdb7580c,
56 0x71160cf8f38b0465,
57 0x738a37935f3b71c9,
58 0x756fe46e378bf133,
59 0x7856d2aa2fc5f2b5,
60 0x7bd3b063946e10ae,
61 0x7d8220e1772428d7,
62 0x7e222815078cb97b,
63 0x7ef5bc471d5456c7,
64 0x7fb82baa4ae611dc,
65 0x00bb7aa3d73f6658,
66 0x0190a0f3c55062c5,
67 0x05898e3445512a6e,
68 0x07bfe89cf1bd76ac,
69 0x08dfa7ebe304ee3e,
70 0x0c43165633977bca,
71 0x0e104273b18918b0,
72 0x0fd6ba8608faa6a9,
73 0x10b4139a6b17b224,
74 0x1466cc4fc92a0fa6,
75 0x162ba6008389068a,
76 0x1804116d591ef1fb,
77 0x1c513770474911bd,
78 0x1e7035e7b5183923,
79 0x2114dab846e19e25,
80 0x222ce77c2b3328fc,
81 0x244441ed79830182,
82 0x249b23b50fc204db,
83 0x278aacfcb88c92d6,
84 0x289d52af46e5fa6a,
85 0x2bdec922478c0421,
86 0x2d44f14348a4c5dc,
87 0x2f0c1249e96b6d8d,
88 0x30addc7e975c5045,
89 0x322aedaa0fc32ac8,
90 0x33deef5e1f90ac34,
91 0x343eef5e1f90ac35,
92 0x35ef1de1f7f14439,
93 0x3854faba79ea92ec,
94 0x47f52d02c7e14af7,
95 0x4a6bb6979ae39c49,
96 0x4c85564fb098c955,
97 0x4e80fde34c996086,
98 0x4ed9a2c2a34ac2f9,
99 0x51a3274280201a89,
100 0x574fe0403124a00e,
101 0x581561def4a9ee31,
102 0x5b55ed1f039cebff,
103 0x5e2780695036a679,
104 0x624be064a3fb2725,
105 0x674dcfee6690ffc6,
106 0x6a6cc08102f0da5b,
107 0x6be6c9e14b7c22c4,
108 0x6ce75d226331d03a,
109 0x6d5b9445072f4374,
110 0x6e927edd0dbb8c09,
111 0x71060cf8f38b0465,
112 0x71b1d7cb7eae05d9,
113 0x72fba10d818fdafd,
114 0x739a37935f3b71c9,
115 0x755fe46e378bf133,
116 0x76603d7cb98edc59,
117 0x78447e17e7814ce7,
118 0x799d696737fe68c7,
119 0x7ade779fddf21622,
120 0x7c1c283ffc61c87d,
121 0x7d1a85c6f7fba05d,
122 0x7da220e1772428d7,
123 0x7e022815078cb97b,
124 0x7e9a9b45a91f1700,
125 0x7ee3c8eeb77b8d05,
126 0x7f13c8eeb77b8d05,
127 0x7f6594223f5654bf,
128 0x7fd82baa4ae611dc,
129 0x002d243f646eaf51,
130 0x00f5d15b26b80e30,
131 0x0180a0f3c55062c5,
132 0x01f393b456eef178,
133 0x05798e3445512a6e,
134 0x06afdadafcacdf85,
135 0x06e8b03fd6894b66,
136 0x07cfe89cf1bd76ac,
137 0x08ac25584881552a,
138 0x097822507db6a8fd,
139 0x0c27b35936d56e28,
140 0x0c53165633977bca,
141 0x0c8e9eddbbb259b4,
142 0x0e204273b18918b0,
143 0x0f1d16d6d4b89689,
144 0x0fe6ba8608faa6a9,
145 0x105f48347c60a1be,
146 0x13627383c5456c5e,
147 0x13f93bb1e72a2033,
148 0x148048cb468bc208,
149 0x1514c0b3a63c1444,
150 0x175090684f5fe997,
151 0x17e4116d591ef1fb,
152 0x18cde996371c6060,
153 0x19aa2cf604c30d3f,
154 0x1d2b1ad9101b1bfd,
155 0x1e5035e7b5183923,
156 0x1fe5a79c4e71d028,
157 0x20ec29bc6879dfcd,
158 0x218ce77c2b3328fb,
159 0x221ce77c2b3328fc,
160 0x233f346f9ed36b89,
161 0x243441ed79830182,
162 0x245441ed79830182,
163 0x247441ed79830182,
164 0x2541e4ee41180c0a,
165 0x277aacfcb88c92d6,
166 0x279aacfcb88c92d6,
167 0x27cbb4c6bd8601bd,
168 0x28c04a616046e074,
169 0x2a4eeff57768f88c,
170 0x2c2379f099a86227,
171 0x2d04f14348a4c5db,
172 0x2d54f14348a4c5dc,
173 0x2d6a8c931c19b77a,
174 0x2fa387cf9cb4ad4e,
175 0x308ddc7e975c5046,
176 0x3149190e30e46c1d,
177 0x318d2ec75df6ba2a,
178 0x32548050091c3c24,
179 0x33beef5e1f90ac34,
180 0x33feef5e1f90ac35,
181 0x342eef5e1f90ac35,
182 0x345eef5e1f90ac35,
183 0x35108621c4199208,
184 0x366b870de5d93270,
185 0x375b20c2f4f8d4a0,
186 0x3864faba79ea92ec,
187 0x3aa78cfcab31064c,
188 0x4919d9577de925d5,
189 0x49ccadd6dd730c96,
190 0x4b9a32ac316fb3ab,
191 0x4bba32ac316fb3ab,
192 0x4cff20b1a0d7f626,
193 0x4e3e2785c3a2a20b,
194 0x4ea9a2c2a34ac2f9,
195 0x4ec9a2c2a34ac2f9,
196 0x4f28750ea732fdae,
197 0x513843e10734fa57,
198 0x51e71760b3c0bc13,
199 0x55693ba3249a8511,
200 0x57763ae2caed4528,
201 0x57f561def4a9ee32,
202 0x584561def4a9ee31,
203 0x5b45ed1f039cebfe,
204 0x5bfaf5b5378aa2e5,
205 0x5c6cf45d333da323,
206 0x5e64ec8fd70420c7,
207 0x6009813653f62db7,
208 0x64112a13daa46fe4,
209 0x672dcfee6690ffc6,
210 0x677a77581053543b,
211 0x699873e3758bc6b3,
212 0x6b3ef9beaa7aa584,
213 0x6b7b86d8c3df7cd1,
214 0x6bf6c9e14b7c22c3,
215 0x6c16c9e14b7c22c3,
216 0x6d075d226331d03a,
217 0x6d5a3bdac4f00f33,
218 0x6e4a2fbffdb7580c,
219 0x6e927edd0dbb8c08,
220 0x6ee1c382c3819a0a,
221 0x70f60cf8f38b0465,
222 0x7114390c68b888ce,
223 0x714fb4840532a9e5,
224 0x727fca36c06cf106,
225 0x72eba10d818fdafd,
226 0x737a37935f3b71c9,
227 0x73972852443155ae,
228 0x754fe46e378bf132,
229 0x755fe46e378bf132,
230 0x756fe46e378bf132,
231 0x76603d7cb98edc58,
232 0x76703d7cb98edc58,
233 0x782f7c6a9ad432a1,
234 0x78547e17e7814ce7,
235 0x7964066d88c7cab8,
236 0x7ace779fddf21621,
237 0x7ade779fddf21621,
238 0x7bc3b063946e10ae,
239 0x7c0c283ffc61c87d,
240 0x7c31926c7a7122ba,
241 0x7d0a85c6f7fba05d,
242 0x7d52a5daf9226f04,
243 0x7d9220e1772428d7,
244 0x7db220e1772428d7,
245 0x7dfe5aceedf1c1f1,
246 0x7e122815078cb97b,
247 0x7e8a9b45a91f1700,
248 0x7eb6202598194bee,
249 0x7ec6202598194bee,
250 0x7ef3c8eeb77b8d05,
251 0x7f03c8eeb77b8d05,
252 0x7f23c8eeb77b8d05,
253 0x7f5594223f5654bf,
254 0x7f9914e03c9260ee,
255 0x7fc82baa4ae611dc,
256 0x7fefffffffffffff,
257 0x001d243f646eaf51,
258 0x00ab7aa3d73f6658,
259 0x00cb7aa3d73f6658,
260 0x010b7aa3d73f6658,
261 0x012b7aa3d73f6658,
262 0x0180a0f3c55062c6,
263 0x0190a0f3c55062c6,
264 0x03719f08ccdccfe5,
265 0x03dc25ba6a45de02,
266 0x05798e3445512a6f,
267 0x05898e3445512a6f,
268 0x06bfdadafcacdf85,
269 0x06cfdadafcacdf85,
270 0x06f8b03fd6894b66,
271 0x07c1707c02068785,
272 0x08567a3c8dc4bc9c,
273 0x089c25584881552a,
274 0x08dfa7ebe304ee3d,
275 0x096822507db6a8fd,
276 0x09e41934d77659be,
277 0x0c27b35936d56e27,
278 0x0c43165633977bc9,
279 0x0c53165633977bc9,
280 0x0c63165633977bc9,
281 0x0c7e9eddbbb259b4,
282 0x0c9e9eddbbb259b4,
283 0x0e104273b18918b1,
284 0x0e204273b18918b1,
285 0x0e304273b18918b1,
286 0x0fd6ba8608faa6a8,
287 0x0fe6ba8608faa6a8,
288 0x1006b100e18e5c17,
289 0x104f48347c60a1be,
290 0x10a4139a6b17b224,
291 0x12cb91d317c8ebe9,
292 0x138fb24e492936f6,
293 0x13afb24e492936f6,
294 0x14093bb1e72a2033,
295 0x1476cc4fc92a0fa6,
296 0x149048cb468bc209,
297 0x1504c0b3a63c1444,
298 0x161ba6008389068a,
299 0x168cfab1a09b49c4,
300 0x175090684f5fe998,
301 0x176090684f5fe998,
302 0x17f4116d591ef1fb,
303 0x18a710b7a2ef18b7,
304 0x18d99fccca44882a,
305 0x199a2cf604c30d3f,
306 0x1b5ebddc6593c857,
307 0x1d1b1ad9101b1bfd,
308 0x1d3b1ad9101b1bfd,
309 0x1e4035e7b5183923,
310 0x1e6035e7b5183923,
311 0x1fd5a79c4e71d028,
312 0x20cc29bc6879dfcd,
313 0x20e8823a57adbef8,
314 0x2104dab846e19e25,
315 0x2124dab846e19e25,
316 0x220ce77c2b3328fb,
317 0x221ce77c2b3328fb,
318 0x222ce77c2b3328fb,
319 0x229197b290631476,
320 0x240a28877a09a4e0,
321 0x243441ed79830181,
322 0x244441ed79830181,
323 0x245441ed79830181,
324 0x246441ed79830181,
325 0x247441ed79830181,
326 0x248b23b50fc204db,
327 0x24ab23b50fc204db,
328 0x2633dc6227de9148,
329 0x2653dc6227de9148,
330 0x277aacfcb88c92d7,
331 0x278aacfcb88c92d7,
332 0x279aacfcb88c92d7,
333 0x27bbb4c6bd8601bd,
334 0x289d52af46e5fa69,
335 0x28b04a616046e074,
336 0x28d04a616046e074,
337 0x2a3eeff57768f88c,
338 0x2b8e3a0aeed7be19,
339 0x2beec922478c0421,
340 0x2cc7c3fba45c1271,
341 0x2cf4f14348a4c5db,
342 0x2d44f14348a4c5db,
343 0x2d54f14348a4c5db,
344 0x2d5a8c931c19b77a,
345 0x2d64f14348a4c5dc,
346 0x2efc1249e96b6d8d,
347 0x2f0f6b23cfe98807,
348 0x2fe91b9de4d5cf31,
349 0x308ddc7e975c5045,
350 0x309ddc7e975c5045,
351 0x30bddc7e975c5045,
352 0x3150ed9bd6bfd003,
353 0x317d2ec75df6ba2a,
354 0x321aedaa0fc32ac8,
355 0x32448050091c3c24,
356 0x328f5a18504dfaac,
357 0x3336dca59d035820,
358 0x33ceef5e1f90ac34,
359 0x33eeef5e1f90ac35,
360 0x340eef5e1f90ac35,
361 0x34228f9edfbd3420,
362 0x34328f9edfbd3420,
363 0x344eef5e1f90ac35,
364 0x346eef5e1f90ac35,
365 0x35008621c4199208,
366 0x35e0ac2e7f90b8a3,
367 0x361dde4a4ab13e09,
368 0x367b870de5d93270,
369 0x375b20c2f4f8d49f,
370 0x37f25d342b1e33e5,
371 0x3854faba79ea92ed,
372 0x3864faba79ea92ed,
373 0x3a978cfcab31064d,
374 0x3aa78cfcab31064d,
375 0x490cd230a7ff47c3,
376 0x4929d9577de925d5,
377 0x4939d9577de925d5,
378 0x49dcadd6dd730c96,
379 0x4a7bb6979ae39c49,
380 0x4b9a32ac316fb3ac,
381 0x4baa32ac316fb3ac,
382 0x4bba32ac316fb3ac,
383 0x4cef20b1a0d7f626,
384 0x4e2e2785c3a2a20a,
385 0x4e3e2785c3a2a20a,
386 0x4e6454b1aef62c8d,
387 0x4e90fde34c996086,
388 0x4ea9a2c2a34ac2fa,
389 0x4eb9a2c2a34ac2fa,
390 0x4ec9a2c2a34ac2fa,
391 0x4ed9a2c2a34ac2fa,
392 0x4f38750ea732fdae,
393 0x504ca9bade45b94a,
394 0x514843e10734fa57,
395 0x51b3274280201a89,
396 0x521f6a5025e71a61,
397 0x52c6a47d4e7ec633,
398 0x55793ba3249a8511,
399 0x575fe0403124a00e,
400 0x57863ae2caed4528,
401 0x57e561def4a9ee32,
402 0x580561def4a9ee31,
403 0x582561def4a9ee31,
404 0x585561def4a9ee31,
405 0x59d0dd8f2788d699,
406 0x5b55ed1f039cebfe,
407 0x5beaf5b5378aa2e5,
408 0x5c0af5b5378aa2e5,
409 0x5c4ef3052ef0a361,
410 0x5e1780695036a679,
411 0x5e54ec8fd70420c7,
412 0x5e6b5e2f86026f05,
413 0x5faaeac2d1ea2695,
414 0x611260322d04d50b,
415 0x625be064a3fb2725,
416 0x64212a13daa46fe4,
417 0x671dcfee6690ffc6,
418 0x673dcfee6690ffc6,
419 0x675dcfee6690ffc6,
420 0x678a77581053543b,
421 0x682d3683fa3d1ee0,
422 0x699cb490951e8515,
423 0x6b3ef9beaa7aa583,
424 0x6b4ef9beaa7aa583,
425 0x6b7896beb0c66eb9,
426 0x6bdf20938e7414bb,
427 0x6bef20938e7414bb,
428 0x6bf6c9e14b7c22c4,
429 0x6c06c9e14b7c22c4,
430 0x6c16c9e14b7c22c4,
431 0x6cf75d226331d03a,
432 0x6d175d226331d03a,
433 0x6d4b9445072f4374,
434};
435
436const Slab = struct {
437 str: []const u8,
438 exp: i32,
439};
440
441fn slab(str: []const u8, exp: i32) Slab {
442 return Slab{
443 .str = str,
444 .exp = exp,
445 };
446}
447
448pub const enum3_data = [_]Slab{
449 slab("40648030339495312", 69),
450 slab("4498645355592131", -134),
451 slab("678321594594593", 244),
452 slab("36539702510912277", -230),
453 slab("56819570380646536", -70),
454 slab("42452693975546964", 175),
455 slab("34248868699178663", 291),
456 slab("34037810581283983", -267),
457 slab("67135881167178176", -188),
458 slab("74973710847373845", -108),
459 slab("60272377639347644", -45),
460 slab("1316415380484425", 116),
461 slab("64433314612521525", 218),
462 slab("31961502891542243", 263),
463 slab("4407140524515149", 303),
464 slab("69928982131052126", -291),
465 slab("5331838923808276", -248),
466 slab("24766435002945523", -208),
467 slab("21509066976048781", -149),
468 slab("2347200170470694", -123),
469 slab("51404180294474556", -89),
470 slab("12320586499023201", -56),
471 slab("38099461575161174", 45),
472 slab("3318949537676913", 79),
473 slab("48988560059074597", 136),
474 slab("7955843973866726", 209),
475 slab("2630089515909384", 227),
476 slab("11971601492124911", 258),
477 slab("35394816534699092", 284),
478 slab("47497368114750945", 299),
479 slab("54271187548763685", 305),
480 slab("2504414972009504", -302),
481 slab("69316187906522606", -275),
482 slab("53263359599109627", -252),
483 slab("24384437085962037", -239),
484 slab("3677854139813342", -213),
485 slab("44318030915155535", -195),
486 slab("28150140033551147", -162),
487 slab("1157373742186464", -143),
488 slab("2229658838863212", -132),
489 slab("67817280930489786", -117),
490 slab("56966478488538934", -92),
491 slab("49514357246452655", -74),
492 slab("74426102121433776", -64),
493 slab("78851753593748485", -55),
494 slab("19024128529074359", -25),
495 slab("32118580932839778", 57),
496 slab("17693166778887419", 72),
497 slab("78117757194253536", 88),
498 slab("56627018760181905", 122),
499 slab("35243988108650928", 153),
500 slab("38624526316654214", 194),
501 slab("2397422026462446", 213),
502 slab("37862966954556723", 224),
503 slab("56089100059334965", 237),
504 slab("3666156212014994", 249),
505 slab("47886405968499643", 258),
506 slab("48228872759189434", 272),
507 slab("29980574575739863", 289),
508 slab("37049827284413546", 297),
509 slab("37997894491800756", 300),
510 slab("37263572163337027", 304),
511 slab("16973149506391291", 308),
512 slab("391314839376485", -304),
513 slab("38797447671091856", -300),
514 slab("54994366114768736", -281),
515 slab("23593494977819109", -270),
516 slab("61359116592542813", -265),
517 slab("1332959730952069", -248),
518 slab("6096109271490509", -240),
519 slab("22874741188249992", -231),
520 slab("33104948806015703", -227),
521 slab("21670630627577332", -209),
522 slab("70547825868713855", -201),
523 slab("54981742371928845", -192),
524 slab("27843818440071113", -171),
525 slab("4504022405368184", -161),
526 slab("2548351460621656", -148),
527 slab("4629494968745856", -143),
528 slab("557414709715803", -133),
529 slab("23897004381644022", -131),
530 slab("33057350728075958", -117),
531 slab("47628822744182433", -112),
532 slab("22520091703825729", -96),
533 slab("1285104507361864", -89),
534 slab("46239793787746783", -81),
535 slab("330095714976351", -73),
536 slab("4994144928421182", -66),
537 slab("77003665618895", -58),
538 slab("49282345996092803", -56),
539 slab("66534156679273626", -48),
540 slab("24661175471861008", -36),
541 slab("45035996273704964", 39),
542 slab("32402369146794532", 51),
543 slab("42859354584576066", 61),
544 slab("1465909318208761", 71),
545 slab("70772667115549675", 72),
546 slab("18604316837693468", 86),
547 slab("38329392744333992", 113),
548 slab("21062646087750798", 117),
549 slab("972708181182949", 132),
550 slab("36683053719290777", 146),
551 slab("32106017483029628", 166),
552 slab("41508952543121158", 190),
553 slab("45072812455233127", 205),
554 slab("59935550661561155", 212),
555 slab("40270821632825953", 217),
556 slab("60846862848160256", 219),
557 slab("42788225889846894", 225),
558 slab("28044550029667482", 237),
559 slab("46475406389115295", 240),
560 slab("7546114860200514", 246),
561 slab("7332312424029988", 249),
562 slab("23943202984249821", 258),
563 slab("15980751445771122", 263),
564 slab("21652206566352648", 272),
565 slab("65171333649148234", 278),
566 slab("70789633069398184", 284),
567 slab("68600253110025576", 290),
568 slab("4234784709771466", 295),
569 slab("14819930913765419", 298),
570 slab("9499473622950189", 299),
571 slab("71272819274635585", 302),
572 slab("16959746108988652", 304),
573 slab("13567796887190921", 305),
574 slab("4735325513114182", 306),
575 slab("67892598025565165", 308),
576 slab("81052743999542975", -307),
577 slab("4971131903427841", -303),
578 slab("19398723835545928", -300),
579 slab("29232758945460627", -298),
580 slab("27497183057384368", -281),
581 slab("17970091719480621", -275),
582 slab("22283747288943228", -274),
583 slab("47186989955638217", -270),
584 slab("6819439187504402", -266),
585 slab("47902021250710456", -262),
586 slab("41378294570975613", -249),
587 slab("2665919461904138", -248),
588 slab("3421423777071132", -247),
589 slab("12192218542981019", -239),
590 slab("7147520638007367", -235),
591 slab("45749482376499984", -231),
592 slab("80596937390013985", -229),
593 slab("26761990828289327", -214),
594 slab("18738512510673039", -211),
595 slab("619160875073638", -209),
596 slab("403997300048931", -206),
597 slab("22159015457577768", -195),
598 slab("13745435592982211", -192),
599 slab("33567940583589088", -188),
600 slab("4812711195250522", -184),
601 slab("3591036630219558", -167),
602 slab("1126005601342046", -161),
603 slab("5047135806497922", -154),
604 slab("43018133952097563", -149),
605 slab("45209911804158747", -146),
606 slab("2314747484372928", -143),
607 slab("65509428048152994", -138),
608 slab("2787073548579015", -133),
609 slab("1114829419431606", -132),
610 slab("4459317677726424", -132),
611 slab("32269008655522087", -128),
612 slab("16528675364037979", -117),
613 slab("66114701456151916", -117),
614 slab("54934856534126976", -116),
615 slab("21168365664081082", -111),
616 slab("67445733463759384", -104),
617 slab("45590931008842566", -95),
618 slab("8031903171011649", -91),
619 slab("2570209014723728", -89),
620 slab("6516605505584466", -89),
621 slab("32943123175907307", -78),
622 slab("82523928744087755", -74),
623 slab("28409785190323268", -70),
624 slab("52853886779813977", -69),
625 slab("30417302377115577", -65),
626 slab("1925091640472375", -58),
627 slab("30801466247558002", -57),
628 slab("24641172998046401", -56),
629 slab("19712938398437121", -55),
630 slab("43129529027318865", -52),
631 slab("15068094409836911", -45),
632 slab("48658418478920193", -41),
633 slab("49322350943722016", -36),
634 slab("38048257058148717", -25),
635 slab("14411294198511291", 45),
636 slab("32745697577386472", 48),
637 slab("16059290466419889", 57),
638 slab("64237161865679556", 57),
639 slab("8003248329710242", 63),
640 slab("81296060678990625", 69),
641 slab("8846583389443709", 71),
642 slab("35386333557774838", 72),
643 slab("21606114462319112", 74),
644 slab("18413733104063271", 84),
645 slab("35887030159858487", 87),
646 slab("2825769263311679", 104),
647 slab("2138446062528161", 114),
648 slab("52656615219377", 116),
649 slab("16850116870200639", 118),
650 slab("48635409059147446", 132),
651 slab("12247140014768649", 136),
652 slab("16836228873919609", 138),
653 slab("5225574770881846", 147),
654 slab("42745323906998127", 155),
655 slab("10613173493886741", 175),
656 slab("10377238135780289", 190),
657 slab("29480080280199528", 191),
658 slab("4679330956996797", 201),
659 slab("3977921986933363", 209),
660 slab("56560320317673966", 210),
661 slab("1198711013231223", 213),
662 slab("4794844052924892", 213),
663 slab("16108328653130381", 218),
664 slab("57878622568856074", 219),
665 slab("18931483477278361", 224),
666 slab("4278822588984689", 225),
667 slab("1315044757954692", 227),
668 slab("14022275014833741", 237),
669 slab("5143975308105889", 237),
670 slab("64517311884236306", 238),
671 slab("3391607972972965", 244),
672 slab("3773057430100257", 246),
673 slab("1833078106007497", 249),
674 slab("64766168833734675", 249),
675 slab("1197160149212491", 258),
676 slab("2394320298424982", 258),
677 slab("4788640596849964", 258),
678 slab("1598075144577112", 263),
679 slab("3196150289154224", 263),
680 slab("83169412421960475", 271),
681 slab("43304413132705296", 272),
682 slab("5546524276967009", 277),
683 slab("3539481653469909", 284),
684 slab("7078963306939818", 284),
685 slab("14990287287869931", 289),
686 slab("34300126555012788", 290),
687 slab("17124434349589332", 291),
688 slab("2117392354885733", 295),
689 slab("47639264836707725", 296),
690 slab("7409965456882709", 297),
691 slab("29639861827530837", 298),
692 slab("79407577493590275", 299),
693 slab("18998947245900378", 300),
694 slab("35636409637317792", 302),
695 slab("23707742595255608", 303),
696 slab("47415485190511216", 303),
697 slab("33919492217977303", 304),
698 slab("6783898443595461", 304),
699 slab("27135593774381842", 305),
700 slab("2367662756557091", 306),
701 slab("44032152438472327", 307),
702 slab("33946299012782582", 308),
703 slab("17976931348623157", 309),
704 slab("40526371999771488", -307),
705 slab("1956574196882425", -304),
706 slab("78262967875297", -304),
707 slab("1252207486004752", -302),
708 slab("5008829944019008", -302),
709 slab("1939872383554593", -300),
710 slab("3879744767109186", -300),
711 slab("44144884605471774", -291),
712 slab("45129663866844427", -289),
713 slab("2749718305738437", -281),
714 slab("5499436611476874", -281),
715 slab("35940183438961242", -275),
716 slab("71880366877922484", -275),
717 slab("44567494577886457", -274),
718 slab("25789638850173173", -270),
719 slab("17018905290641991", -267),
720 slab("3409719593752201", -266),
721 slab("6135911659254281", -265),
722 slab("23951010625355228", -262),
723 slab("51061856989121905", -260),
724 slab("4137829457097561", -249),
725 slab("13329597309520689", -248),
726 slab("26659194619041378", -248),
727 slab("53318389238082755", -248),
728 slab("1710711888535566", -247),
729 slab("6842847554142264", -247),
730 slab("609610927149051", -240),
731 slab("1219221854298102", -239),
732 slab("2438443708596204", -239),
733 slab("2287474118824999", -231),
734 slab("4574948237649998", -231),
735 slab("18269851255456139", -230),
736 slab("40298468695006992", -229),
737 slab("16552474403007851", -227),
738 slab("39050270537318193", -217),
739 slab("1838927069906671", -213),
740 slab("7355708279626684", -213),
741 slab("37477025021346077", -211),
742 slab("43341261255154663", -209),
743 slab("12383217501472761", -208),
744 slab("2019986500244655", -206),
745 slab("35273912934356928", -201),
746 slab("47323883490786093", -199),
747 slab("2215901545757777", -195),
748 slab("4431803091515554", -195),
749 slab("27490871185964422", -192),
750 slab("64710073234908765", -189),
751 slab("57511323531737074", -188),
752 slab("2406355597625261", -184),
753 slab("75862936714499446", -176),
754 slab("1795518315109779", -167),
755 slab("7182073260439116", -167),
756 slab("563002800671023", -162),
757 slab("2252011202684092", -161),
758 slab("2523567903248961", -154),
759 slab("10754533488024391", -149),
760 slab("37436263604934127", -149),
761 slab("1274175730310828", -148),
762 slab("5096702921243312", -148),
763 slab("11573737421864639", -143),
764 slab("23147474843729279", -143),
765 slab("46294949687458557", -143),
766 slab("36067106647774144", -141),
767 slab("44986453555921307", -134),
768 slab("27870735485790148", -133),
769 slab("55741470971580295", -133),
770 slab("11148294194316059", -132),
771 slab("22296588388632118", -132),
772 slab("44593176777264236", -132),
773 slab("11948502190822011", -131),
774 slab("47794008763288043", -131),
775 slab("1173600085235347", -123),
776 slab("4694400340941388", -123),
777 slab("1652867536403798", -117),
778 slab("3305735072807596", -117),
779 slab("6611470145615192", -117),
780 slab("27467428267063488", -116),
781 slab("4762882274418243", -112),
782 slab("10584182832040541", -111),
783 slab("42336731328162165", -111),
784 slab("33722866731879692", -104),
785 slab("69097540994131414", -98),
786 slab("45040183407651457", -96),
787 slab("5696647848853893", -92),
788 slab("40159515855058247", -91),
789 slab("12851045073618639", -89),
790 slab("25702090147237278", -89),
791 slab("3258302752792233", -89),
792 slab("5140418029447456", -89),
793 slab("23119896893873391", -81),
794 slab("51753157237874753", -81),
795 slab("67761208324172855", -77),
796 slab("8252392874408775", -74),
797 slab("1650478574881755", -73),
798 slab("660191429952702", -73),
799 slab("3832399419240467", -70),
800 slab("26426943389906988", -69),
801 slab("2497072464210591", -66),
802 slab("15208651188557789", -65),
803 slab("37213051060716888", -64),
804 slab("55574205388093594", -61),
805 slab("385018328094475", -58),
806 slab("15400733123779001", -57),
807 slab("61602932495116004", -57),
808 slab("14784703798827841", -56),
809 slab("29569407597655683", -56),
810 slab("9856469199218561", -56),
811 slab("39425876796874242", -55),
812 slab("21564764513659432", -52),
813 slab("35649516398744314", -48),
814 slab("51091836539008967", -47),
815 slab("30136188819673822", -45),
816 slab("4865841847892019", -41),
817 slab("33729482964455627", -38),
818 slab("2466117547186101", -36),
819 slab("4932235094372202", -36),
820 slab("1902412852907436", -25),
821 slab("3804825705814872", -25),
822 slab("80341375308088225", 44),
823 slab("28822588397022582", 45),
824 slab("57645176794045164", 45),
825 slab("65491395154772944", 48),
826 slab("64804738293589064", 51),
827 slab("1605929046641989", 57),
828 slab("3211858093283978", 57),
829 slab("6423716186567956", 57),
830 slab("4001624164855121", 63),
831 slab("4064803033949531", 69),
832 slab("8129606067899062", 69),
833 slab("4384946084578497", 70),
834 slab("2931818636417522", 71),
835 slab("884658338944371", 71),
836 slab("1769316677888742", 72),
837 slab("3538633355777484", 72),
838 slab("7077266711554968", 72),
839 slab("43212228924638223", 74),
840 slab("6637899075353826", 79),
841 slab("36827466208126543", 84),
842 slab("37208633675386937", 86),
843 slab("39058878597126768", 88),
844 slab("57654578150150385", 91),
845 slab("5651538526623358", 104),
846 slab("76658785488667984", 113),
847 slab("4276892125056322", 114),
848 slab("263283076096885", 116),
849 slab("10531323043875399", 117),
850 slab("42125292175501597", 117),
851 slab("33700233740401277", 118),
852 slab("44596066840334405", 125),
853 slab("9727081811829489", 132),
854 slab("61235700073843246", 135),
855 slab("24494280029537298", 136),
856 slab("4499029632233837", 137),
857 slab("18341526859645389", 146),
858 slab("2612787385440923", 147),
859 slab("6834859331393543", 147),
860 slab("70487976217301855", 153),
861 slab("40366692112133834", 160),
862 slab("64212034966059256", 166),
863 slab("21226346987773482", 175),
864 slab("51886190678901447", 189),
865 slab("20754476271560579", 190),
866 slab("83017905086242315", 190),
867 slab("58960160560399056", 191),
868 slab("66641177824100826", 194),
869 slab("5493127645170153", 201),
870 slab("39779219869333628", 209),
871 slab("79558439738667255", 209),
872 slab("50523702331566894", 210),
873 slab("40933393326155808", 212),
874 slab("81866786652311615", 212),
875 slab("11987110132312231", 213),
876 slab("23974220264624462", 213),
877 slab("47948440529248924", 213),
878 slab("8054164326565191", 217),
879 slab("32216657306260762", 218),
880 slab("30423431424080128", 219),
881};
lib/std/fmt/errol/lookup.zig deleted-606
......@@ -1,606 +0,0 @@
1pub const HP = struct {
2 val: f64,
3 off: f64,
4};
5pub const lookup_table = [_]HP{
6 HP{ .val = 1.000000e+308, .off = -1.097906362944045488e+291 },
7 HP{ .val = 1.000000e+307, .off = 1.396894023974354241e+290 },
8 HP{ .val = 1.000000e+306, .off = -1.721606459673645508e+289 },
9 HP{ .val = 1.000000e+305, .off = 6.074644749446353973e+288 },
10 HP{ .val = 1.000000e+304, .off = 6.074644749446353567e+287 },
11 HP{ .val = 1.000000e+303, .off = -1.617650767864564452e+284 },
12 HP{ .val = 1.000000e+302, .off = -7.629703079084895055e+285 },
13 HP{ .val = 1.000000e+301, .off = -5.250476025520442286e+284 },
14 HP{ .val = 1.000000e+300, .off = -5.250476025520441956e+283 },
15 HP{ .val = 1.000000e+299, .off = -5.250476025520441750e+282 },
16 HP{ .val = 1.000000e+298, .off = 4.043379652465702264e+281 },
17 HP{ .val = 1.000000e+297, .off = -1.765280146275637946e+280 },
18 HP{ .val = 1.000000e+296, .off = 1.865132227937699609e+279 },
19 HP{ .val = 1.000000e+295, .off = 1.865132227937699609e+278 },
20 HP{ .val = 1.000000e+294, .off = -6.643646774124810287e+277 },
21 HP{ .val = 1.000000e+293, .off = 7.537651562646039934e+276 },
22 HP{ .val = 1.000000e+292, .off = -1.325659897835741608e+275 },
23 HP{ .val = 1.000000e+291, .off = 4.213909764965371606e+274 },
24 HP{ .val = 1.000000e+290, .off = -6.172783352786715670e+273 },
25 HP{ .val = 1.000000e+289, .off = -6.172783352786715670e+272 },
26 HP{ .val = 1.000000e+288, .off = -7.630473539575035471e+270 },
27 HP{ .val = 1.000000e+287, .off = -7.525217352494018700e+270 },
28 HP{ .val = 1.000000e+286, .off = -3.298861103408696612e+269 },
29 HP{ .val = 1.000000e+285, .off = 1.984084207947955778e+268 },
30 HP{ .val = 1.000000e+284, .off = -7.921438250845767591e+267 },
31 HP{ .val = 1.000000e+283, .off = 4.460464822646386735e+266 },
32 HP{ .val = 1.000000e+282, .off = -3.278224598286209647e+265 },
33 HP{ .val = 1.000000e+281, .off = -3.278224598286209737e+264 },
34 HP{ .val = 1.000000e+280, .off = -3.278224598286209961e+263 },
35 HP{ .val = 1.000000e+279, .off = -5.797329227496039232e+262 },
36 HP{ .val = 1.000000e+278, .off = 3.649313132040821498e+261 },
37 HP{ .val = 1.000000e+277, .off = -2.867878510995372374e+259 },
38 HP{ .val = 1.000000e+276, .off = -5.206914080024985409e+259 },
39 HP{ .val = 1.000000e+275, .off = 4.018322599210230404e+258 },
40 HP{ .val = 1.000000e+274, .off = 7.862171215558236495e+257 },
41 HP{ .val = 1.000000e+273, .off = 5.459765830340732821e+256 },
42 HP{ .val = 1.000000e+272, .off = -6.552261095746788047e+255 },
43 HP{ .val = 1.000000e+271, .off = 4.709014147460262298e+254 },
44 HP{ .val = 1.000000e+270, .off = -4.675381888545612729e+253 },
45 HP{ .val = 1.000000e+269, .off = -4.675381888545612892e+252 },
46 HP{ .val = 1.000000e+268, .off = 2.656177514583977380e+251 },
47 HP{ .val = 1.000000e+267, .off = 2.656177514583977190e+250 },
48 HP{ .val = 1.000000e+266, .off = -3.071603269111014892e+249 },
49 HP{ .val = 1.000000e+265, .off = -6.651466258920385440e+248 },
50 HP{ .val = 1.000000e+264, .off = -4.414051890289528972e+247 },
51 HP{ .val = 1.000000e+263, .off = -1.617283929500958387e+246 },
52 HP{ .val = 1.000000e+262, .off = -1.617283929500958241e+245 },
53 HP{ .val = 1.000000e+261, .off = 7.122615947963323868e+244 },
54 HP{ .val = 1.000000e+260, .off = -6.533477610574617382e+243 },
55 HP{ .val = 1.000000e+259, .off = 7.122615947963323982e+242 },
56 HP{ .val = 1.000000e+258, .off = -5.679971763165996225e+241 },
57 HP{ .val = 1.000000e+257, .off = -3.012765990014054219e+240 },
58 HP{ .val = 1.000000e+256, .off = -3.012765990014054219e+239 },
59 HP{ .val = 1.000000e+255, .off = 1.154743030535854616e+238 },
60 HP{ .val = 1.000000e+254, .off = 6.364129306223240767e+237 },
61 HP{ .val = 1.000000e+253, .off = 6.364129306223241129e+236 },
62 HP{ .val = 1.000000e+252, .off = -9.915202805299840595e+235 },
63 HP{ .val = 1.000000e+251, .off = -4.827911520448877980e+234 },
64 HP{ .val = 1.000000e+250, .off = 7.890316691678530146e+233 },
65 HP{ .val = 1.000000e+249, .off = 7.890316691678529484e+232 },
66 HP{ .val = 1.000000e+248, .off = -4.529828046727141859e+231 },
67 HP{ .val = 1.000000e+247, .off = 4.785280507077111924e+230 },
68 HP{ .val = 1.000000e+246, .off = -6.858605185178205305e+229 },
69 HP{ .val = 1.000000e+245, .off = -4.432795665958347728e+228 },
70 HP{ .val = 1.000000e+244, .off = -7.465057564983169531e+227 },
71 HP{ .val = 1.000000e+243, .off = -7.465057564983169741e+226 },
72 HP{ .val = 1.000000e+242, .off = -5.096102956370027445e+225 },
73 HP{ .val = 1.000000e+241, .off = -5.096102956370026952e+224 },
74 HP{ .val = 1.000000e+240, .off = -1.394611380411992474e+223 },
75 HP{ .val = 1.000000e+239, .off = 9.188208545617793960e+221 },
76 HP{ .val = 1.000000e+238, .off = -4.864759732872650359e+221 },
77 HP{ .val = 1.000000e+237, .off = 5.979453868566904629e+220 },
78 HP{ .val = 1.000000e+236, .off = -5.316601966265964857e+219 },
79 HP{ .val = 1.000000e+235, .off = -5.316601966265964701e+218 },
80 HP{ .val = 1.000000e+234, .off = -1.786584517880693123e+217 },
81 HP{ .val = 1.000000e+233, .off = 2.625937292600896716e+216 },
82 HP{ .val = 1.000000e+232, .off = -5.647541102052084079e+215 },
83 HP{ .val = 1.000000e+231, .off = -5.647541102052083888e+214 },
84 HP{ .val = 1.000000e+230, .off = -9.956644432600511943e+213 },
85 HP{ .val = 1.000000e+229, .off = 8.161138937705571862e+211 },
86 HP{ .val = 1.000000e+228, .off = 7.549087847752475275e+211 },
87 HP{ .val = 1.000000e+227, .off = -9.283347037202319948e+210 },
88 HP{ .val = 1.000000e+226, .off = 3.866992716668613820e+209 },
89 HP{ .val = 1.000000e+225, .off = 7.154577655136347262e+208 },
90 HP{ .val = 1.000000e+224, .off = 3.045096482051680688e+207 },
91 HP{ .val = 1.000000e+223, .off = -4.660180717482069567e+206 },
92 HP{ .val = 1.000000e+222, .off = -4.660180717482070101e+205 },
93 HP{ .val = 1.000000e+221, .off = -4.660180717482069544e+204 },
94 HP{ .val = 1.000000e+220, .off = 3.562757926310489022e+202 },
95 HP{ .val = 1.000000e+219, .off = 3.491561111451748149e+202 },
96 HP{ .val = 1.000000e+218, .off = -8.265758834125874135e+201 },
97 HP{ .val = 1.000000e+217, .off = 3.981449442517482365e+200 },
98 HP{ .val = 1.000000e+216, .off = -2.142154695804195936e+199 },
99 HP{ .val = 1.000000e+215, .off = 9.339603063548950188e+198 },
100 HP{ .val = 1.000000e+214, .off = 4.555537330485139746e+197 },
101 HP{ .val = 1.000000e+213, .off = 1.565496247320257804e+196 },
102 HP{ .val = 1.000000e+212, .off = 9.040598955232462036e+195 },
103 HP{ .val = 1.000000e+211, .off = 4.368659762787334780e+194 },
104 HP{ .val = 1.000000e+210, .off = 7.288621758065539072e+193 },
105 HP{ .val = 1.000000e+209, .off = -7.311188218325485628e+192 },
106 HP{ .val = 1.000000e+208, .off = 1.813693016918905189e+191 },
107 HP{ .val = 1.000000e+207, .off = -3.889357755108838992e+190 },
108 HP{ .val = 1.000000e+206, .off = -3.889357755108838992e+189 },
109 HP{ .val = 1.000000e+205, .off = -1.661603547285501360e+188 },
110 HP{ .val = 1.000000e+204, .off = 1.123089212493670643e+187 },
111 HP{ .val = 1.000000e+203, .off = 1.123089212493670643e+186 },
112 HP{ .val = 1.000000e+202, .off = 9.825254086803583029e+185 },
113 HP{ .val = 1.000000e+201, .off = -3.771878529305654999e+184 },
114 HP{ .val = 1.000000e+200, .off = 3.026687778748963675e+183 },
115 HP{ .val = 1.000000e+199, .off = -9.720624048853446693e+182 },
116 HP{ .val = 1.000000e+198, .off = -1.753554156601940139e+181 },
117 HP{ .val = 1.000000e+197, .off = 4.885670753607648963e+180 },
118 HP{ .val = 1.000000e+196, .off = 4.885670753607648963e+179 },
119 HP{ .val = 1.000000e+195, .off = 2.292223523057028076e+178 },
120 HP{ .val = 1.000000e+194, .off = 5.534032561245303825e+177 },
121 HP{ .val = 1.000000e+193, .off = -6.622751331960730683e+176 },
122 HP{ .val = 1.000000e+192, .off = -4.090088020876139692e+175 },
123 HP{ .val = 1.000000e+191, .off = -7.255917159731877552e+174 },
124 HP{ .val = 1.000000e+190, .off = -7.255917159731877992e+173 },
125 HP{ .val = 1.000000e+189, .off = -2.309309130269787104e+172 },
126 HP{ .val = 1.000000e+188, .off = -2.309309130269787019e+171 },
127 HP{ .val = 1.000000e+187, .off = 9.284303438781988230e+170 },
128 HP{ .val = 1.000000e+186, .off = 2.038295583124628364e+169 },
129 HP{ .val = 1.000000e+185, .off = 2.038295583124628532e+168 },
130 HP{ .val = 1.000000e+184, .off = -1.735666841696912925e+167 },
131 HP{ .val = 1.000000e+183, .off = 5.340512704843477241e+166 },
132 HP{ .val = 1.000000e+182, .off = -6.453119872723839321e+165 },
133 HP{ .val = 1.000000e+181, .off = 8.288920849235306587e+164 },
134 HP{ .val = 1.000000e+180, .off = -9.248546019891598293e+162 },
135 HP{ .val = 1.000000e+179, .off = 1.954450226518486016e+162 },
136 HP{ .val = 1.000000e+178, .off = -5.243811844750628197e+161 },
137 HP{ .val = 1.000000e+177, .off = -7.448980502074320639e+159 },
138 HP{ .val = 1.000000e+176, .off = -7.448980502074319858e+158 },
139 HP{ .val = 1.000000e+175, .off = 6.284654753766312753e+158 },
140 HP{ .val = 1.000000e+174, .off = -6.895756753684458388e+157 },
141 HP{ .val = 1.000000e+173, .off = -1.403918625579970616e+156 },
142 HP{ .val = 1.000000e+172, .off = -8.268716285710580522e+155 },
143 HP{ .val = 1.000000e+171, .off = 4.602779327034313170e+154 },
144 HP{ .val = 1.000000e+170, .off = -3.441905430931244940e+153 },
145 HP{ .val = 1.000000e+169, .off = 6.613950516525702884e+152 },
146 HP{ .val = 1.000000e+168, .off = 6.613950516525702652e+151 },
147 HP{ .val = 1.000000e+167, .off = -3.860899428741951187e+150 },
148 HP{ .val = 1.000000e+166, .off = 5.959272394946474605e+149 },
149 HP{ .val = 1.000000e+165, .off = 1.005101065481665103e+149 },
150 HP{ .val = 1.000000e+164, .off = -1.783349948587918355e+146 },
151 HP{ .val = 1.000000e+163, .off = 6.215006036188360099e+146 },
152 HP{ .val = 1.000000e+162, .off = 6.215006036188360099e+145 },
153 HP{ .val = 1.000000e+161, .off = -3.774589324822814903e+144 },
154 HP{ .val = 1.000000e+160, .off = -6.528407745068226929e+142 },
155 HP{ .val = 1.000000e+159, .off = 7.151530601283157561e+142 },
156 HP{ .val = 1.000000e+158, .off = 4.712664546348788765e+141 },
157 HP{ .val = 1.000000e+157, .off = 1.664081977680827856e+140 },
158 HP{ .val = 1.000000e+156, .off = 1.664081977680827750e+139 },
159 HP{ .val = 1.000000e+155, .off = -7.176231540910168265e+137 },
160 HP{ .val = 1.000000e+154, .off = -3.694754568805822650e+137 },
161 HP{ .val = 1.000000e+153, .off = 2.665969958768462622e+134 },
162 HP{ .val = 1.000000e+152, .off = -4.625108135904199522e+135 },
163 HP{ .val = 1.000000e+151, .off = -1.717753238721771919e+134 },
164 HP{ .val = 1.000000e+150, .off = 1.916440382756262433e+133 },
165 HP{ .val = 1.000000e+149, .off = -4.897672657515052040e+132 },
166 HP{ .val = 1.000000e+148, .off = -4.897672657515052198e+131 },
167 HP{ .val = 1.000000e+147, .off = 2.200361759434233991e+130 },
168 HP{ .val = 1.000000e+146, .off = 6.636633270027537273e+129 },
169 HP{ .val = 1.000000e+145, .off = 1.091293881785907977e+128 },
170 HP{ .val = 1.000000e+144, .off = -2.374543235865110597e+127 },
171 HP{ .val = 1.000000e+143, .off = -2.374543235865110537e+126 },
172 HP{ .val = 1.000000e+142, .off = -5.082228484029969099e+125 },
173 HP{ .val = 1.000000e+141, .off = -1.697621923823895943e+124 },
174 HP{ .val = 1.000000e+140, .off = -5.928380124081487212e+123 },
175 HP{ .val = 1.000000e+139, .off = -3.284156248920492522e+122 },
176 HP{ .val = 1.000000e+138, .off = -3.284156248920492706e+121 },
177 HP{ .val = 1.000000e+137, .off = -3.284156248920492476e+120 },
178 HP{ .val = 1.000000e+136, .off = -5.866406127007401066e+119 },
179 HP{ .val = 1.000000e+135, .off = 3.817030915818506056e+118 },
180 HP{ .val = 1.000000e+134, .off = 7.851796350329300951e+117 },
181 HP{ .val = 1.000000e+133, .off = -2.235117235947686077e+116 },
182 HP{ .val = 1.000000e+132, .off = 9.170432597638723691e+114 },
183 HP{ .val = 1.000000e+131, .off = 8.797444499042767883e+114 },
184 HP{ .val = 1.000000e+130, .off = -5.978307824605161274e+113 },
185 HP{ .val = 1.000000e+129, .off = 1.782556435814758516e+111 },
186 HP{ .val = 1.000000e+128, .off = -7.517448691651820362e+111 },
187 HP{ .val = 1.000000e+127, .off = 4.507089332150205498e+110 },
188 HP{ .val = 1.000000e+126, .off = 7.513223838100711695e+109 },
189 HP{ .val = 1.000000e+125, .off = 7.513223838100712113e+108 },
190 HP{ .val = 1.000000e+124, .off = 5.164681255326878494e+107 },
191 HP{ .val = 1.000000e+123, .off = 2.229003026859587122e+106 },
192 HP{ .val = 1.000000e+122, .off = -1.440594758724527399e+105 },
193 HP{ .val = 1.000000e+121, .off = -3.734093374714598783e+104 },
194 HP{ .val = 1.000000e+120, .off = 1.999653165260579757e+103 },
195 HP{ .val = 1.000000e+119, .off = 5.583244752745066693e+102 },
196 HP{ .val = 1.000000e+118, .off = 3.343500010567262234e+101 },
197 HP{ .val = 1.000000e+117, .off = -5.055542772599503556e+100 },
198 HP{ .val = 1.000000e+116, .off = -1.555941612946684331e+99 },
199 HP{ .val = 1.000000e+115, .off = -1.555941612946684331e+98 },
200 HP{ .val = 1.000000e+114, .off = -1.555941612946684293e+97 },
201 HP{ .val = 1.000000e+113, .off = -1.555941612946684246e+96 },
202 HP{ .val = 1.000000e+112, .off = 6.988006530736955847e+95 },
203 HP{ .val = 1.000000e+111, .off = 4.318022735835818244e+94 },
204 HP{ .val = 1.000000e+110, .off = -2.356936751417025578e+93 },
205 HP{ .val = 1.000000e+109, .off = 1.814912928116001926e+92 },
206 HP{ .val = 1.000000e+108, .off = -3.399899171300282744e+91 },
207 HP{ .val = 1.000000e+107, .off = 3.118615952970072913e+90 },
208 HP{ .val = 1.000000e+106, .off = -9.103599905036843605e+89 },
209 HP{ .val = 1.000000e+105, .off = 6.174169917471802325e+88 },
210 HP{ .val = 1.000000e+104, .off = -1.915675085734668657e+86 },
211 HP{ .val = 1.000000e+103, .off = -1.915675085734668864e+85 },
212 HP{ .val = 1.000000e+102, .off = 2.295048673475466221e+85 },
213 HP{ .val = 1.000000e+101, .off = 2.295048673475466135e+84 },
214 HP{ .val = 1.000000e+100, .off = -1.590289110975991792e+83 },
215 HP{ .val = 1.000000e+99, .off = 3.266383119588331155e+82 },
216 HP{ .val = 1.000000e+98, .off = 2.309629754856292029e+80 },
217 HP{ .val = 1.000000e+97, .off = -7.357587384771124533e+80 },
218 HP{ .val = 1.000000e+96, .off = -4.986165397190889509e+79 },
219 HP{ .val = 1.000000e+95, .off = -2.021887912715594741e+78 },
220 HP{ .val = 1.000000e+94, .off = -2.021887912715594638e+77 },
221 HP{ .val = 1.000000e+93, .off = -4.337729697461918675e+76 },
222 HP{ .val = 1.000000e+92, .off = -4.337729697461918997e+75 },
223 HP{ .val = 1.000000e+91, .off = -7.956232486128049702e+74 },
224 HP{ .val = 1.000000e+90, .off = 3.351588728453609882e+73 },
225 HP{ .val = 1.000000e+89, .off = 5.246334248081951113e+71 },
226 HP{ .val = 1.000000e+88, .off = 4.058327554364963672e+71 },
227 HP{ .val = 1.000000e+87, .off = 4.058327554364963918e+70 },
228 HP{ .val = 1.000000e+86, .off = -1.463069523067487266e+69 },
229 HP{ .val = 1.000000e+85, .off = -1.463069523067487314e+68 },
230 HP{ .val = 1.000000e+84, .off = -5.776660989811589441e+67 },
231 HP{ .val = 1.000000e+83, .off = -3.080666323096525761e+66 },
232 HP{ .val = 1.000000e+82, .off = 3.659320343691134468e+65 },
233 HP{ .val = 1.000000e+81, .off = 7.871812010433421235e+64 },
234 HP{ .val = 1.000000e+80, .off = -2.660986470836727449e+61 },
235 HP{ .val = 1.000000e+79, .off = 3.264399249934044627e+62 },
236 HP{ .val = 1.000000e+78, .off = -8.493621433689703070e+60 },
237 HP{ .val = 1.000000e+77, .off = 1.721738727445414063e+60 },
238 HP{ .val = 1.000000e+76, .off = -4.706013449590547218e+59 },
239 HP{ .val = 1.000000e+75, .off = 7.346021882351880518e+58 },
240 HP{ .val = 1.000000e+74, .off = 4.835181188197207515e+57 },
241 HP{ .val = 1.000000e+73, .off = 1.696630320503867482e+56 },
242 HP{ .val = 1.000000e+72, .off = 5.619818905120542959e+55 },
243 HP{ .val = 1.000000e+71, .off = -4.188152556421145598e+54 },
244 HP{ .val = 1.000000e+70, .off = -7.253143638152923145e+53 },
245 HP{ .val = 1.000000e+69, .off = -7.253143638152923145e+52 },
246 HP{ .val = 1.000000e+68, .off = 4.719477774861832896e+51 },
247 HP{ .val = 1.000000e+67, .off = 1.726322421608144052e+50 },
248 HP{ .val = 1.000000e+66, .off = 5.467766613175255107e+49 },
249 HP{ .val = 1.000000e+65, .off = 7.909613737163661911e+47 },
250 HP{ .val = 1.000000e+64, .off = -2.132041900945439564e+47 },
251 HP{ .val = 1.000000e+63, .off = -5.785795994272697265e+46 },
252 HP{ .val = 1.000000e+62, .off = -3.502199685943161329e+45 },
253 HP{ .val = 1.000000e+61, .off = 5.061286470292598274e+44 },
254 HP{ .val = 1.000000e+60, .off = 5.061286470292598472e+43 },
255 HP{ .val = 1.000000e+59, .off = 2.831211950439536034e+42 },
256 HP{ .val = 1.000000e+58, .off = 5.618805100255863927e+41 },
257 HP{ .val = 1.000000e+57, .off = -4.834669211555366251e+40 },
258 HP{ .val = 1.000000e+56, .off = -9.190283508143378583e+39 },
259 HP{ .val = 1.000000e+55, .off = -1.023506702040855158e+38 },
260 HP{ .val = 1.000000e+54, .off = -7.829154040459624616e+37 },
261 HP{ .val = 1.000000e+53, .off = 6.779051325638372659e+35 },
262 HP{ .val = 1.000000e+52, .off = 6.779051325638372290e+34 },
263 HP{ .val = 1.000000e+51, .off = 6.779051325638371598e+33 },
264 HP{ .val = 1.000000e+50, .off = -7.629769841091887392e+33 },
265 HP{ .val = 1.000000e+49, .off = 5.350972305245182400e+32 },
266 HP{ .val = 1.000000e+48, .off = -4.384584304507619764e+31 },
267 HP{ .val = 1.000000e+47, .off = -4.384584304507619876e+30 },
268 HP{ .val = 1.000000e+46, .off = 6.860180964052978705e+28 },
269 HP{ .val = 1.000000e+45, .off = 7.024271097546444878e+28 },
270 HP{ .val = 1.000000e+44, .off = -8.821361405306422641e+27 },
271 HP{ .val = 1.000000e+43, .off = -1.393721169594140991e+26 },
272 HP{ .val = 1.000000e+42, .off = -4.488571267807591679e+25 },
273 HP{ .val = 1.000000e+41, .off = -6.200086450407783195e+23 },
274 HP{ .val = 1.000000e+40, .off = -3.037860284270036669e+23 },
275 HP{ .val = 1.000000e+39, .off = 6.029083362839682141e+22 },
276 HP{ .val = 1.000000e+38, .off = 2.251190176543965970e+21 },
277 HP{ .val = 1.000000e+37, .off = 4.612373417978788577e+20 },
278 HP{ .val = 1.000000e+36, .off = -4.242063737401796198e+19 },
279 HP{ .val = 1.000000e+35, .off = 3.136633892082024448e+18 },
280 HP{ .val = 1.000000e+34, .off = 5.442476901295718400e+17 },
281 HP{ .val = 1.000000e+33, .off = 5.442476901295718400e+16 },
282 HP{ .val = 1.000000e+32, .off = -5.366162204393472000e+15 },
283 HP{ .val = 1.000000e+31, .off = 3.641037050347520000e+14 },
284 HP{ .val = 1.000000e+30, .off = -1.988462483865600000e+13 },
285 HP{ .val = 1.000000e+29, .off = 8.566849142784000000e+12 },
286 HP{ .val = 1.000000e+28, .off = 4.168802631680000000e+11 },
287 HP{ .val = 1.000000e+27, .off = -1.328755507200000000e+10 },
288 HP{ .val = 1.000000e+26, .off = -4.764729344000000000e+09 },
289 HP{ .val = 1.000000e+25, .off = -9.059696640000000000e+08 },
290 HP{ .val = 1.000000e+24, .off = 1.677721600000000000e+07 },
291 HP{ .val = 1.000000e+23, .off = 8.388608000000000000e+06 },
292 HP{ .val = 1.000000e+22, .off = 0.000000000000000000e+00 },
293 HP{ .val = 1.000000e+21, .off = 0.000000000000000000e+00 },
294 HP{ .val = 1.000000e+20, .off = 0.000000000000000000e+00 },
295 HP{ .val = 1.000000e+19, .off = 0.000000000000000000e+00 },
296 HP{ .val = 1.000000e+18, .off = 0.000000000000000000e+00 },
297 HP{ .val = 1.000000e+17, .off = 0.000000000000000000e+00 },
298 HP{ .val = 1.000000e+16, .off = 0.000000000000000000e+00 },
299 HP{ .val = 1.000000e+15, .off = 0.000000000000000000e+00 },
300 HP{ .val = 1.000000e+14, .off = 0.000000000000000000e+00 },
301 HP{ .val = 1.000000e+13, .off = 0.000000000000000000e+00 },
302 HP{ .val = 1.000000e+12, .off = 0.000000000000000000e+00 },
303 HP{ .val = 1.000000e+11, .off = 0.000000000000000000e+00 },
304 HP{ .val = 1.000000e+10, .off = 0.000000000000000000e+00 },
305 HP{ .val = 1.000000e+09, .off = 0.000000000000000000e+00 },
306 HP{ .val = 1.000000e+08, .off = 0.000000000000000000e+00 },
307 HP{ .val = 1.000000e+07, .off = 0.000000000000000000e+00 },
308 HP{ .val = 1.000000e+06, .off = 0.000000000000000000e+00 },
309 HP{ .val = 1.000000e+05, .off = 0.000000000000000000e+00 },
310 HP{ .val = 1.000000e+04, .off = 0.000000000000000000e+00 },
311 HP{ .val = 1.000000e+03, .off = 0.000000000000000000e+00 },
312 HP{ .val = 1.000000e+02, .off = 0.000000000000000000e+00 },
313 HP{ .val = 1.000000e+01, .off = 0.000000000000000000e+00 },
314 HP{ .val = 1.000000e+00, .off = 0.000000000000000000e+00 },
315 HP{ .val = 1.000000e-01, .off = -5.551115123125783010e-18 },
316 HP{ .val = 1.000000e-02, .off = -2.081668171172168436e-19 },
317 HP{ .val = 1.000000e-03, .off = -2.081668171172168557e-20 },
318 HP{ .val = 1.000000e-04, .off = -4.792173602385929943e-21 },
319 HP{ .val = 1.000000e-05, .off = -8.180305391403130547e-22 },
320 HP{ .val = 1.000000e-06, .off = 4.525188817411374069e-23 },
321 HP{ .val = 1.000000e-07, .off = 4.525188817411373922e-24 },
322 HP{ .val = 1.000000e-08, .off = -2.092256083012847109e-25 },
323 HP{ .val = 1.000000e-09, .off = -6.228159145777985254e-26 },
324 HP{ .val = 1.000000e-10, .off = -3.643219731549774344e-27 },
325 HP{ .val = 1.000000e-11, .off = 6.050303071806019080e-28 },
326 HP{ .val = 1.000000e-12, .off = 2.011335237074438524e-29 },
327 HP{ .val = 1.000000e-13, .off = -3.037374556340037101e-30 },
328 HP{ .val = 1.000000e-14, .off = 1.180690645440101289e-32 },
329 HP{ .val = 1.000000e-15, .off = -7.770539987666107583e-32 },
330 HP{ .val = 1.000000e-16, .off = 2.090221327596539779e-33 },
331 HP{ .val = 1.000000e-17, .off = -7.154242405462192144e-34 },
332 HP{ .val = 1.000000e-18, .off = -7.154242405462192572e-35 },
333 HP{ .val = 1.000000e-19, .off = 2.475407316473986894e-36 },
334 HP{ .val = 1.000000e-20, .off = 5.484672854579042914e-37 },
335 HP{ .val = 1.000000e-21, .off = 9.246254777210362522e-38 },
336 HP{ .val = 1.000000e-22, .off = -4.859677432657087182e-39 },
337 HP{ .val = 1.000000e-23, .off = 3.956530198510069291e-40 },
338 HP{ .val = 1.000000e-24, .off = 7.629950044829717753e-41 },
339 HP{ .val = 1.000000e-25, .off = -3.849486974919183692e-42 },
340 HP{ .val = 1.000000e-26, .off = -3.849486974919184170e-43 },
341 HP{ .val = 1.000000e-27, .off = -3.849486974919184070e-44 },
342 HP{ .val = 1.000000e-28, .off = 2.876745653839937870e-45 },
343 HP{ .val = 1.000000e-29, .off = 5.679342582489572168e-46 },
344 HP{ .val = 1.000000e-30, .off = -8.333642060758598930e-47 },
345 HP{ .val = 1.000000e-31, .off = -8.333642060758597958e-48 },
346 HP{ .val = 1.000000e-32, .off = -5.596730997624190224e-49 },
347 HP{ .val = 1.000000e-33, .off = -5.596730997624190604e-50 },
348 HP{ .val = 1.000000e-34, .off = 7.232539610818348498e-51 },
349 HP{ .val = 1.000000e-35, .off = -7.857545194582380514e-53 },
350 HP{ .val = 1.000000e-36, .off = 5.896157255772251528e-53 },
351 HP{ .val = 1.000000e-37, .off = -6.632427322784915796e-54 },
352 HP{ .val = 1.000000e-38, .off = 3.808059826012723592e-55 },
353 HP{ .val = 1.000000e-39, .off = 7.070712060011985131e-56 },
354 HP{ .val = 1.000000e-40, .off = 7.070712060011985584e-57 },
355 HP{ .val = 1.000000e-41, .off = -5.761291134237854167e-59 },
356 HP{ .val = 1.000000e-42, .off = -3.762312935688689794e-59 },
357 HP{ .val = 1.000000e-43, .off = -7.745042713519821150e-60 },
358 HP{ .val = 1.000000e-44, .off = 4.700987842202462817e-61 },
359 HP{ .val = 1.000000e-45, .off = 1.589480203271891964e-62 },
360 HP{ .val = 1.000000e-46, .off = -2.299904345391321765e-63 },
361 HP{ .val = 1.000000e-47, .off = 2.561826340437695261e-64 },
362 HP{ .val = 1.000000e-48, .off = 2.561826340437695345e-65 },
363 HP{ .val = 1.000000e-49, .off = 6.360053438741614633e-66 },
364 HP{ .val = 1.000000e-50, .off = -7.616223705782342295e-68 },
365 HP{ .val = 1.000000e-51, .off = -7.616223705782343324e-69 },
366 HP{ .val = 1.000000e-52, .off = -7.616223705782342295e-70 },
367 HP{ .val = 1.000000e-53, .off = -3.079876214757872338e-70 },
368 HP{ .val = 1.000000e-54, .off = -3.079876214757872821e-71 },
369 HP{ .val = 1.000000e-55, .off = 5.423954167728123147e-73 },
370 HP{ .val = 1.000000e-56, .off = -3.985444122640543680e-73 },
371 HP{ .val = 1.000000e-57, .off = 4.504255013759498850e-74 },
372 HP{ .val = 1.000000e-58, .off = -2.570494266573869991e-75 },
373 HP{ .val = 1.000000e-59, .off = -2.570494266573869930e-76 },
374 HP{ .val = 1.000000e-60, .off = 2.956653608686574324e-77 },
375 HP{ .val = 1.000000e-61, .off = -3.952281235388981376e-78 },
376 HP{ .val = 1.000000e-62, .off = -3.952281235388981376e-79 },
377 HP{ .val = 1.000000e-63, .off = -6.651083908855995172e-80 },
378 HP{ .val = 1.000000e-64, .off = 3.469426116645307030e-81 },
379 HP{ .val = 1.000000e-65, .off = 7.686305293937516319e-82 },
380 HP{ .val = 1.000000e-66, .off = 2.415206322322254927e-83 },
381 HP{ .val = 1.000000e-67, .off = 5.709643179581793251e-84 },
382 HP{ .val = 1.000000e-68, .off = -6.644495035141475923e-85 },
383 HP{ .val = 1.000000e-69, .off = 3.650620143794581913e-86 },
384 HP{ .val = 1.000000e-70, .off = 4.333966503770636492e-88 },
385 HP{ .val = 1.000000e-71, .off = 8.476455383920859113e-88 },
386 HP{ .val = 1.000000e-72, .off = 3.449543675455986564e-89 },
387 HP{ .val = 1.000000e-73, .off = 3.077238576654418974e-91 },
388 HP{ .val = 1.000000e-74, .off = 4.234998629903623140e-91 },
389 HP{ .val = 1.000000e-75, .off = 4.234998629903623412e-92 },
390 HP{ .val = 1.000000e-76, .off = 7.303182045714702338e-93 },
391 HP{ .val = 1.000000e-77, .off = 7.303182045714701699e-94 },
392 HP{ .val = 1.000000e-78, .off = 1.121271649074855759e-96 },
393 HP{ .val = 1.000000e-79, .off = 1.121271649074855863e-97 },
394 HP{ .val = 1.000000e-80, .off = 3.857468248661243988e-97 },
395 HP{ .val = 1.000000e-81, .off = 3.857468248661244248e-98 },
396 HP{ .val = 1.000000e-82, .off = 3.857468248661244410e-99 },
397 HP{ .val = 1.000000e-83, .off = -3.457651055545315679e-100 },
398 HP{ .val = 1.000000e-84, .off = -3.457651055545315933e-101 },
399 HP{ .val = 1.000000e-85, .off = 2.257285900866059216e-102 },
400 HP{ .val = 1.000000e-86, .off = -8.458220892405268345e-103 },
401 HP{ .val = 1.000000e-87, .off = -1.761029146610688867e-104 },
402 HP{ .val = 1.000000e-88, .off = 6.610460535632536565e-105 },
403 HP{ .val = 1.000000e-89, .off = -3.853901567171494935e-106 },
404 HP{ .val = 1.000000e-90, .off = 5.062493089968513723e-108 },
405 HP{ .val = 1.000000e-91, .off = -2.218844988608365240e-108 },
406 HP{ .val = 1.000000e-92, .off = 1.187522883398155383e-109 },
407 HP{ .val = 1.000000e-93, .off = 9.703442563414457296e-110 },
408 HP{ .val = 1.000000e-94, .off = 4.380992763404268896e-111 },
409 HP{ .val = 1.000000e-95, .off = 1.054461638397900823e-112 },
410 HP{ .val = 1.000000e-96, .off = 9.370789450913819736e-113 },
411 HP{ .val = 1.000000e-97, .off = -3.623472756142303998e-114 },
412 HP{ .val = 1.000000e-98, .off = 6.122223899149788839e-115 },
413 HP{ .val = 1.000000e-99, .off = -1.999189980260288281e-116 },
414 HP{ .val = 1.000000e-100, .off = -1.999189980260288281e-117 },
415 HP{ .val = 1.000000e-101, .off = -5.171617276904849634e-118 },
416 HP{ .val = 1.000000e-102, .off = 6.724985085512256320e-119 },
417 HP{ .val = 1.000000e-103, .off = 4.246526260008692213e-120 },
418 HP{ .val = 1.000000e-104, .off = 7.344599791888147003e-121 },
419 HP{ .val = 1.000000e-105, .off = 3.472007877038828407e-122 },
420 HP{ .val = 1.000000e-106, .off = 5.892377823819652194e-123 },
421 HP{ .val = 1.000000e-107, .off = -1.585470431324073925e-125 },
422 HP{ .val = 1.000000e-108, .off = -3.940375084977444795e-125 },
423 HP{ .val = 1.000000e-109, .off = 7.869099673288519908e-127 },
424 HP{ .val = 1.000000e-110, .off = -5.122196348054018581e-127 },
425 HP{ .val = 1.000000e-111, .off = -8.815387795168313713e-128 },
426 HP{ .val = 1.000000e-112, .off = 5.034080131510290214e-129 },
427 HP{ .val = 1.000000e-113, .off = 2.148774313452247863e-130 },
428 HP{ .val = 1.000000e-114, .off = -5.064490231692858416e-131 },
429 HP{ .val = 1.000000e-115, .off = -5.064490231692858166e-132 },
430 HP{ .val = 1.000000e-116, .off = 5.708726942017560559e-134 },
431 HP{ .val = 1.000000e-117, .off = -2.951229134482377772e-134 },
432 HP{ .val = 1.000000e-118, .off = 1.451398151372789513e-135 },
433 HP{ .val = 1.000000e-119, .off = -1.300243902286690040e-136 },
434 HP{ .val = 1.000000e-120, .off = 2.139308664787659449e-137 },
435 HP{ .val = 1.000000e-121, .off = 2.139308664787659329e-138 },
436 HP{ .val = 1.000000e-122, .off = -5.922142664292847471e-139 },
437 HP{ .val = 1.000000e-123, .off = -5.922142664292846912e-140 },
438 HP{ .val = 1.000000e-124, .off = 6.673875037395443799e-141 },
439 HP{ .val = 1.000000e-125, .off = -1.198636026159737932e-142 },
440 HP{ .val = 1.000000e-126, .off = 5.361789860136246995e-143 },
441 HP{ .val = 1.000000e-127, .off = -2.838742497733733936e-144 },
442 HP{ .val = 1.000000e-128, .off = -5.401408859568103261e-145 },
443 HP{ .val = 1.000000e-129, .off = 7.411922949603743011e-146 },
444 HP{ .val = 1.000000e-130, .off = -8.604741811861064385e-147 },
445 HP{ .val = 1.000000e-131, .off = 1.405673664054439890e-148 },
446 HP{ .val = 1.000000e-132, .off = 1.405673664054439933e-149 },
447 HP{ .val = 1.000000e-133, .off = -6.414963426504548053e-150 },
448 HP{ .val = 1.000000e-134, .off = -3.971014335704864578e-151 },
449 HP{ .val = 1.000000e-135, .off = -3.971014335704864748e-152 },
450 HP{ .val = 1.000000e-136, .off = -1.523438813303585576e-154 },
451 HP{ .val = 1.000000e-137, .off = 2.234325152653707766e-154 },
452 HP{ .val = 1.000000e-138, .off = -6.715683724786540160e-155 },
453 HP{ .val = 1.000000e-139, .off = -2.986513359186437306e-156 },
454 HP{ .val = 1.000000e-140, .off = 1.674949597813692102e-157 },
455 HP{ .val = 1.000000e-141, .off = -4.151879098436469092e-158 },
456 HP{ .val = 1.000000e-142, .off = -4.151879098436469295e-159 },
457 HP{ .val = 1.000000e-143, .off = 4.952540739454407825e-160 },
458 HP{ .val = 1.000000e-144, .off = 4.952540739454407667e-161 },
459 HP{ .val = 1.000000e-145, .off = 8.508954738630531443e-162 },
460 HP{ .val = 1.000000e-146, .off = -2.604839008794855481e-163 },
461 HP{ .val = 1.000000e-147, .off = 2.952057864917838382e-164 },
462 HP{ .val = 1.000000e-148, .off = 6.425118410988271757e-165 },
463 HP{ .val = 1.000000e-149, .off = 2.083792728400229858e-166 },
464 HP{ .val = 1.000000e-150, .off = -6.295358232172964237e-168 },
465 HP{ .val = 1.000000e-151, .off = 6.153785555826519421e-168 },
466 HP{ .val = 1.000000e-152, .off = -6.564942029880634994e-169 },
467 HP{ .val = 1.000000e-153, .off = -3.915207116191644540e-170 },
468 HP{ .val = 1.000000e-154, .off = 2.709130168030831503e-171 },
469 HP{ .val = 1.000000e-155, .off = -1.431080634608215966e-172 },
470 HP{ .val = 1.000000e-156, .off = -4.018712386257620994e-173 },
471 HP{ .val = 1.000000e-157, .off = 5.684906682427646782e-174 },
472 HP{ .val = 1.000000e-158, .off = -6.444617153428937489e-175 },
473 HP{ .val = 1.000000e-159, .off = 1.136335243981427681e-176 },
474 HP{ .val = 1.000000e-160, .off = 1.136335243981427725e-177 },
475 HP{ .val = 1.000000e-161, .off = -2.812077463003137395e-178 },
476 HP{ .val = 1.000000e-162, .off = 4.591196362592922204e-179 },
477 HP{ .val = 1.000000e-163, .off = 7.675893789924613703e-180 },
478 HP{ .val = 1.000000e-164, .off = 3.820022005759999543e-181 },
479 HP{ .val = 1.000000e-165, .off = -9.998177244457686588e-183 },
480 HP{ .val = 1.000000e-166, .off = -4.012217555824373639e-183 },
481 HP{ .val = 1.000000e-167, .off = -2.467177666011174334e-185 },
482 HP{ .val = 1.000000e-168, .off = -4.953592503130188139e-185 },
483 HP{ .val = 1.000000e-169, .off = -2.011795792799518887e-186 },
484 HP{ .val = 1.000000e-170, .off = 1.665450095113817423e-187 },
485 HP{ .val = 1.000000e-171, .off = 1.665450095113817487e-188 },
486 HP{ .val = 1.000000e-172, .off = -4.080246604750770577e-189 },
487 HP{ .val = 1.000000e-173, .off = -4.080246604750770677e-190 },
488 HP{ .val = 1.000000e-174, .off = 4.085789420184387951e-192 },
489 HP{ .val = 1.000000e-175, .off = 4.085789420184388146e-193 },
490 HP{ .val = 1.000000e-176, .off = 4.085789420184388146e-194 },
491 HP{ .val = 1.000000e-177, .off = 4.792197640035244894e-194 },
492 HP{ .val = 1.000000e-178, .off = 4.792197640035244742e-195 },
493 HP{ .val = 1.000000e-179, .off = -2.057206575616014662e-196 },
494 HP{ .val = 1.000000e-180, .off = -2.057206575616014662e-197 },
495 HP{ .val = 1.000000e-181, .off = -4.732755097354788053e-198 },
496 HP{ .val = 1.000000e-182, .off = -4.732755097354787867e-199 },
497 HP{ .val = 1.000000e-183, .off = -5.522105321379546765e-201 },
498 HP{ .val = 1.000000e-184, .off = -5.777891238658996019e-201 },
499 HP{ .val = 1.000000e-185, .off = 7.542096444923057046e-203 },
500 HP{ .val = 1.000000e-186, .off = 8.919335748431433483e-203 },
501 HP{ .val = 1.000000e-187, .off = -1.287071881492476028e-204 },
502 HP{ .val = 1.000000e-188, .off = 5.091932887209967018e-205 },
503 HP{ .val = 1.000000e-189, .off = -6.868701054107114024e-206 },
504 HP{ .val = 1.000000e-190, .off = -1.885103578558330118e-207 },
505 HP{ .val = 1.000000e-191, .off = -1.885103578558330205e-208 },
506 HP{ .val = 1.000000e-192, .off = -9.671974634103305058e-209 },
507 HP{ .val = 1.000000e-193, .off = -4.805180224387695640e-210 },
508 HP{ .val = 1.000000e-194, .off = -1.763433718315439838e-211 },
509 HP{ .val = 1.000000e-195, .off = -9.367799983496079132e-212 },
510 HP{ .val = 1.000000e-196, .off = -4.615071067758179837e-213 },
511 HP{ .val = 1.000000e-197, .off = 1.325840076914194777e-214 },
512 HP{ .val = 1.000000e-198, .off = 8.751979007754662425e-215 },
513 HP{ .val = 1.000000e-199, .off = 1.789973760091724198e-216 },
514 HP{ .val = 1.000000e-200, .off = 1.789973760091724077e-217 },
515 HP{ .val = 1.000000e-201, .off = 5.416018159916171171e-218 },
516 HP{ .val = 1.000000e-202, .off = -3.649092839644947067e-219 },
517 HP{ .val = 1.000000e-203, .off = -3.649092839644947067e-220 },
518 HP{ .val = 1.000000e-204, .off = -1.080338554413850956e-222 },
519 HP{ .val = 1.000000e-205, .off = -1.080338554413850841e-223 },
520 HP{ .val = 1.000000e-206, .off = -2.874486186850417807e-223 },
521 HP{ .val = 1.000000e-207, .off = 7.499710055933455072e-224 },
522 HP{ .val = 1.000000e-208, .off = -9.790617015372999087e-225 },
523 HP{ .val = 1.000000e-209, .off = -4.387389805589732612e-226 },
524 HP{ .val = 1.000000e-210, .off = -4.387389805589732612e-227 },
525 HP{ .val = 1.000000e-211, .off = -8.608661063232909897e-228 },
526 HP{ .val = 1.000000e-212, .off = 4.582811616902018972e-229 },
527 HP{ .val = 1.000000e-213, .off = 4.582811616902019155e-230 },
528 HP{ .val = 1.000000e-214, .off = 8.705146829444184930e-231 },
529 HP{ .val = 1.000000e-215, .off = -4.177150709750081830e-232 },
530 HP{ .val = 1.000000e-216, .off = -4.177150709750082366e-233 },
531 HP{ .val = 1.000000e-217, .off = -8.202868690748290237e-234 },
532 HP{ .val = 1.000000e-218, .off = -3.170721214500530119e-235 },
533 HP{ .val = 1.000000e-219, .off = -3.170721214500529857e-236 },
534 HP{ .val = 1.000000e-220, .off = 7.606440013180328441e-238 },
535 HP{ .val = 1.000000e-221, .off = -1.696459258568569049e-238 },
536 HP{ .val = 1.000000e-222, .off = -4.767838333426821244e-239 },
537 HP{ .val = 1.000000e-223, .off = 2.910609353718809138e-240 },
538 HP{ .val = 1.000000e-224, .off = -1.888420450747209784e-241 },
539 HP{ .val = 1.000000e-225, .off = 4.110366804835314035e-242 },
540 HP{ .val = 1.000000e-226, .off = 7.859608839574391006e-243 },
541 HP{ .val = 1.000000e-227, .off = 5.516332567862468419e-244 },
542 HP{ .val = 1.000000e-228, .off = -3.270953451057244613e-245 },
543 HP{ .val = 1.000000e-229, .off = -6.932322625607124670e-246 },
544 HP{ .val = 1.000000e-230, .off = -4.643966891513449762e-247 },
545 HP{ .val = 1.000000e-231, .off = 1.076922443720738305e-248 },
546 HP{ .val = 1.000000e-232, .off = -2.498633390800628939e-249 },
547 HP{ .val = 1.000000e-233, .off = 4.205533798926934891e-250 },
548 HP{ .val = 1.000000e-234, .off = 4.205533798926934891e-251 },
549 HP{ .val = 1.000000e-235, .off = 4.205533798926934697e-252 },
550 HP{ .val = 1.000000e-236, .off = -4.523850562697497656e-253 },
551 HP{ .val = 1.000000e-237, .off = 9.320146633177728298e-255 },
552 HP{ .val = 1.000000e-238, .off = 9.320146633177728062e-256 },
553 HP{ .val = 1.000000e-239, .off = -7.592774752331086440e-256 },
554 HP{ .val = 1.000000e-240, .off = 3.063212017229987840e-257 },
555 HP{ .val = 1.000000e-241, .off = 3.063212017229987562e-258 },
556 HP{ .val = 1.000000e-242, .off = 3.063212017229987562e-259 },
557 HP{ .val = 1.000000e-243, .off = 4.616527473176159842e-261 },
558 HP{ .val = 1.000000e-244, .off = 6.965550922098544975e-261 },
559 HP{ .val = 1.000000e-245, .off = 6.965550922098544749e-262 },
560 HP{ .val = 1.000000e-246, .off = 4.424965697574744679e-263 },
561 HP{ .val = 1.000000e-247, .off = -1.926497363734756420e-264 },
562 HP{ .val = 1.000000e-248, .off = 2.043167049583681740e-265 },
563 HP{ .val = 1.000000e-249, .off = -5.399953725388390154e-266 },
564 HP{ .val = 1.000000e-250, .off = -5.399953725388389982e-267 },
565 HP{ .val = 1.000000e-251, .off = -1.523328321757102663e-268 },
566 HP{ .val = 1.000000e-252, .off = 5.745344310051561161e-269 },
567 HP{ .val = 1.000000e-253, .off = -6.369110076296211879e-270 },
568 HP{ .val = 1.000000e-254, .off = 8.773957906638504842e-271 },
569 HP{ .val = 1.000000e-255, .off = -6.904595826956931908e-273 },
570 HP{ .val = 1.000000e-256, .off = 2.267170882721243669e-273 },
571 HP{ .val = 1.000000e-257, .off = 2.267170882721243669e-274 },
572 HP{ .val = 1.000000e-258, .off = 4.577819683828225398e-275 },
573 HP{ .val = 1.000000e-259, .off = -6.975424321706684210e-276 },
574 HP{ .val = 1.000000e-260, .off = 3.855741933482293648e-277 },
575 HP{ .val = 1.000000e-261, .off = 1.599248963651256552e-278 },
576 HP{ .val = 1.000000e-262, .off = -1.221367248637539543e-279 },
577 HP{ .val = 1.000000e-263, .off = -1.221367248637539494e-280 },
578 HP{ .val = 1.000000e-264, .off = -1.221367248637539647e-281 },
579 HP{ .val = 1.000000e-265, .off = 1.533140771175737943e-282 },
580 HP{ .val = 1.000000e-266, .off = 1.533140771175737895e-283 },
581 HP{ .val = 1.000000e-267, .off = 1.533140771175738074e-284 },
582 HP{ .val = 1.000000e-268, .off = 4.223090009274641634e-285 },
583 HP{ .val = 1.000000e-269, .off = 4.223090009274641634e-286 },
584 HP{ .val = 1.000000e-270, .off = -4.183001359784432924e-287 },
585 HP{ .val = 1.000000e-271, .off = 3.697709298708449474e-288 },
586 HP{ .val = 1.000000e-272, .off = 6.981338739747150474e-289 },
587 HP{ .val = 1.000000e-273, .off = -9.436808465446354751e-290 },
588 HP{ .val = 1.000000e-274, .off = 3.389869038611071740e-291 },
589 HP{ .val = 1.000000e-275, .off = 6.596538414625427829e-292 },
590 HP{ .val = 1.000000e-276, .off = -9.436808465446354618e-293 },
591 HP{ .val = 1.000000e-277, .off = 3.089243784609725523e-294 },
592 HP{ .val = 1.000000e-278, .off = 6.220756847123745836e-295 },
593 HP{ .val = 1.000000e-279, .off = -5.522417137303829470e-296 },
594 HP{ .val = 1.000000e-280, .off = 4.263561183052483059e-297 },
595 HP{ .val = 1.000000e-281, .off = -1.852675267170212272e-298 },
596 HP{ .val = 1.000000e-282, .off = -1.852675267170212378e-299 },
597 HP{ .val = 1.000000e-283, .off = 5.314789322934508480e-300 },
598 HP{ .val = 1.000000e-284, .off = -3.644541414696392675e-301 },
599 HP{ .val = 1.000000e-285, .off = -7.377595888709267777e-302 },
600 HP{ .val = 1.000000e-286, .off = -5.044436842451220838e-303 },
601 HP{ .val = 1.000000e-287, .off = -2.127988034628661760e-304 },
602 HP{ .val = 1.000000e-288, .off = -5.773549044406860911e-305 },
603 HP{ .val = 1.000000e-289, .off = -1.216597782184112068e-306 },
604 HP{ .val = 1.000000e-290, .off = -6.912786859962547924e-307 },
605 HP{ .val = 1.000000e-291, .off = 3.767567660872018813e-308 },
606};
lib/std/fmt/ryu128.zig created+1131
......@@ -0,0 +1,1131 @@
1//! This file implements the ryu floating point conversion algorithm:
2//! https://dl.acm.org/doi/pdf/10.1145/3360595
3
4const std = @import("std");
5
6const special_exponent = 0x7fffffff;
7
8/// Any buffer used for `format` must be at least this large. This is asserted. A runtime check will
9/// additionally be performed if more bytes are required.
10pub const min_buffer_size = 53;
11
12/// Returns the minimum buffer size needed to print every float of a specific type and format.
13pub fn bufferSize(comptime mode: Format, comptime T: type) comptime_int {
14 comptime std.debug.assert(@typeInfo(T) == .Float);
15 return switch (mode) {
16 .scientific => 53,
17 // Based on minimum subnormal values.
18 .decimal => switch (@bitSizeOf(T)) {
19 16 => @max(15, min_buffer_size),
20 32 => 55,
21 64 => 347,
22 80 => 4996,
23 128 => 5011,
24 else => unreachable,
25 },
26 };
27}
28
29pub const RyuError = error{
30 BufferTooSmall,
31};
32
33pub const Format = enum {
34 scientific,
35 decimal,
36};
37
38pub const FormatOptions = struct {
39 mode: Format = .scientific,
40 precision: ?usize = null,
41};
42
43/// Format a floating-point value and write it to buffer. Returns a slice to the buffer containing
44/// the string representation.
45///
46/// Full precision is the default. Any full precision float can be reparsed with std.fmt.parseFloat
47/// unambiguously.
48///
49/// Scientific mode is recommended generally as the output is more compact and any type can be
50/// written in full precision using a buffer of only `min_buffer_size`.
51///
52/// When printing full precision decimals, use `bufferSize` to get the required space. It is
53/// recommended to bound decimal output with a fixed precision to reduce the required buffer size.
54pub fn format(buf: []u8, v_: anytype, options: FormatOptions) RyuError![]const u8 {
55 const v = switch (@TypeOf(v_)) {
56 // comptime_float internally is a f128; this preserves precision.
57 comptime_float => @as(f128, v_),
58 else => v_,
59 };
60
61 const T = @TypeOf(v);
62 comptime std.debug.assert(@typeInfo(T) == .Float);
63 const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
64
65 const has_explicit_leading_bit = std.math.floatMantissaBits(T) - std.math.floatFractionalBits(T) != 0;
66 const d = binaryToDecimal(@as(I, @bitCast(v)), std.math.floatMantissaBits(T), std.math.floatExponentBits(T), has_explicit_leading_bit);
67
68 return switch (options.mode) {
69 .scientific => formatScientific(buf, d, options.precision),
70 .decimal => formatDecimal(buf, d, options.precision),
71 };
72}
73
74pub const FloatDecimal128 = struct {
75 mantissa: u128,
76 exponent: i32,
77 sign: bool,
78};
79
80fn copySpecialStr(buf: []u8, f: FloatDecimal128) []const u8 {
81 if (f.sign) {
82 buf[0] = '-';
83 }
84 const offset: usize = @intFromBool(f.sign);
85 if (f.mantissa != 0) {
86 @memcpy(buf[offset..][0..3], "nan");
87 return buf[0 .. 3 + offset];
88 }
89 @memcpy(buf[offset..][0..3], "inf");
90 return buf[0 .. 3 + offset];
91}
92
93fn writeDecimal(buf: []u8, value: anytype, count: usize) void {
94 var i: usize = 0;
95
96 while (i + 2 < count) : (i += 2) {
97 const c: u8 = @intCast(value.* % 100);
98 value.* /= 100;
99 const d = std.fmt.digits2(c);
100 buf[count - i - 1] = d[1];
101 buf[count - i - 2] = d[0];
102 }
103
104 while (i < count) : (i += 1) {
105 const c: u8 = @intCast(value.* % 10);
106 value.* /= 10;
107 buf[count - i - 1] = '0' + c;
108 }
109}
110
111fn isPowerOf10(n_: u128) bool {
112 var n = n_;
113 while (n != 0) : (n /= 10) {
114 if (n % 10 != 0) return false;
115 }
116 return true;
117}
118
119const RoundMode = enum {
120 /// 1234.56 = precision 2
121 decimal,
122 /// 1.23456e3 = precision 5
123 scientific,
124};
125
126fn round(f: FloatDecimal128, mode: RoundMode, precision: usize) FloatDecimal128 {
127 var round_digit: usize = 0;
128 var output = f.mantissa;
129 var exp = f.exponent;
130 const olength = decimalLength(output);
131
132 switch (mode) {
133 .decimal => {
134 if (f.exponent >= 0) {
135 round_digit = (olength - 1) + precision + @as(usize, @intCast(f.exponent));
136 } else {
137 const min_exp_required = @as(usize, @intCast(-f.exponent));
138 if (precision + olength > min_exp_required) {
139 round_digit = precision + olength - min_exp_required;
140 }
141 }
142 },
143 .scientific => {
144 round_digit = 1 + precision;
145 },
146 }
147
148 if (round_digit < olength) {
149 var nlength = olength;
150 for (round_digit + 1..olength) |_| {
151 output /= 10;
152 exp += 1;
153 nlength -= 1;
154 }
155
156 if (output % 10 >= 5) {
157 output /= 10;
158 output += 1;
159 exp += 1;
160
161 // e.g. 9999 -> 10000
162 if (isPowerOf10(output)) {
163 output /= 10;
164 exp += 1;
165 }
166 }
167 }
168
169 return .{
170 .mantissa = output,
171 .exponent = exp,
172 .sign = f.sign,
173 };
174}
175
176/// Write a FloatDecimal128 to a buffer in scientific form.
177///
178/// The buffer provided must be greater than `min_buffer_size` in length. If no precision is
179/// specified, this function will never return an error. If a precision is specified, up to
180/// `8 + precision` bytes will be written to the buffer. An error will be returned if the content
181/// will not fit.
182///
183/// It is recommended to bound decimal formatting with an exact precision.
184pub fn formatScientific(buf: []u8, f_: FloatDecimal128, precision: ?usize) RyuError![]const u8 {
185 std.debug.assert(buf.len >= min_buffer_size);
186 var f = f_;
187
188 if (f.exponent == special_exponent) {
189 return copySpecialStr(buf, f);
190 }
191
192 if (precision) |prec| {
193 f = round(f, .scientific, prec);
194 }
195
196 var output = f.mantissa;
197 const olength = decimalLength(output);
198
199 if (precision) |prec| {
200 // fixed bound: sign(1) + leading_digit(1) + point(1) + exp_sign(1) + exp_max(4)
201 const req_bytes = 8 + prec;
202 if (buf.len < req_bytes) {
203 return error.BufferTooSmall;
204 }
205 }
206
207 // Step 5: Print the scientific representation
208 var index: usize = 0;
209 if (f.sign) {
210 buf[index] = '-';
211 index += 1;
212 }
213
214 // 1.12345
215 writeDecimal(buf[index + 2 ..], &output, olength - 1);
216 buf[index] = '0' + @as(u8, @intCast(output % 10));
217 buf[index + 1] = '.';
218 index += 2;
219 const dp_index = index;
220 if (olength > 1) index += olength - 1 else index -= 1;
221
222 if (precision) |prec| {
223 index += @intFromBool(olength == 1);
224 if (prec > olength - 1) {
225 const len = prec - (olength - 1);
226 @memset(buf[index..][0..len], '0');
227 index += len;
228 } else {
229 index = dp_index + prec - @intFromBool(prec == 0);
230 }
231 }
232
233 // e100
234 buf[index] = 'e';
235 index += 1;
236 var exp = f.exponent + @as(i32, @intCast(olength)) - 1;
237 if (exp < 0) {
238 buf[index] = '-';
239 index += 1;
240 exp = -exp;
241 }
242 var uexp: u32 = @intCast(exp);
243 const elength = decimalLength(uexp);
244 writeDecimal(buf[index..], &uexp, elength);
245 index += elength;
246
247 return buf[0..index];
248}
249
250/// Write a FloatDecimal128 to a buffer in decimal form.
251///
252/// The buffer provided must be greater than `min_buffer_size` bytes in length. If no precision is
253/// specified, this may still return an error. If precision is specified, `2 + precision` bytes will
254/// always be written.
255pub fn formatDecimal(buf: []u8, f_: FloatDecimal128, precision: ?usize) RyuError![]const u8 {
256 std.debug.assert(buf.len >= min_buffer_size);
257 var f = f_;
258
259 if (f.exponent == special_exponent) {
260 return copySpecialStr(buf, f);
261 }
262
263 if (precision) |prec| {
264 f = round(f, .decimal, prec);
265 }
266
267 var output = f.mantissa;
268 const olength = decimalLength(output);
269
270 // fixed bound: leading_digit(1) + point(1)
271 const req_bytes = if (f.exponent >= 0)
272 2 + @abs(f.exponent) + olength + (precision orelse 0)
273 else
274 2 + @max(@abs(f.exponent) + olength, precision orelse 0);
275 if (buf.len < req_bytes) {
276 return error.BufferTooSmall;
277 }
278
279 // Step 5: Print the decimal representation
280 var index: usize = 0;
281 if (f.sign) {
282 buf[index] = '-';
283 index += 1;
284 }
285
286 const dp_offset = f.exponent + cast_i32(olength);
287 if (dp_offset <= 0) {
288 // 0.000001234
289 buf[index] = '0';
290 buf[index + 1] = '.';
291 index += 2;
292 const dp_index = index;
293
294 const dp_poffset: u32 = @intCast(-dp_offset);
295 @memset(buf[index..][0..dp_poffset], '0');
296 index += dp_poffset;
297 writeDecimal(buf[index..], &output, olength);
298 index += olength;
299
300 if (precision) |prec| {
301 const dp_written = index - dp_index;
302 if (prec > dp_written) {
303 @memset(buf[index..][0 .. prec - dp_written], '0');
304 }
305 index = dp_index + prec - @intFromBool(prec == 0);
306 }
307 } else {
308 // 123456000
309 const dp_uoffset: usize = @intCast(dp_offset);
310 if (dp_uoffset >= olength) {
311 writeDecimal(buf[index..], &output, olength);
312 index += olength;
313 @memset(buf[index..][0 .. dp_uoffset - olength], '0');
314 index += dp_uoffset - olength;
315
316 if (precision) |prec| {
317 if (prec != 0) {
318 buf[index] = '.';
319 index += 1;
320 @memset(buf[index..][0..prec], '0');
321 index += prec;
322 }
323 }
324 } else {
325 // 12345.6789
326 writeDecimal(buf[index + dp_uoffset + 1 ..], &output, olength - dp_uoffset);
327 buf[index + dp_uoffset] = '.';
328 const dp_index = index + dp_uoffset + 1;
329 writeDecimal(buf[index..], &output, dp_uoffset);
330 index += olength + 1;
331
332 if (precision) |prec| {
333 const dp_written = olength - dp_uoffset;
334 if (prec > dp_written) {
335 @memset(buf[index..][0 .. prec - dp_written], '0');
336 }
337 index = dp_index + prec - @intFromBool(prec == 0);
338 }
339 }
340 }
341
342 return buf[0..index];
343}
344
345fn cast_i32(v: anytype) i32 {
346 return @intCast(v);
347}
348
349/// Convert a binary float representation to decimal.
350pub fn binaryToDecimal(bits: u128, mantissa_bits: u7, exponent_bits: u5, explicit_leading_bit: bool) FloatDecimal128 {
351 const bias = (@as(u32, 1) << (exponent_bits - 1)) - 1;
352 const ieee_sign = ((bits >> (mantissa_bits + exponent_bits)) & 1) != 0;
353 const ieee_mantissa = bits & ((@as(u128, 1) << mantissa_bits) - 1);
354 const ieee_exponent: u32 = @intCast((bits >> mantissa_bits) & ((@as(u128, 1) << exponent_bits) - 1));
355
356 if (ieee_exponent == 0 and ieee_mantissa == 0) {
357 return .{
358 .mantissa = 0,
359 .exponent = 0,
360 .sign = ieee_sign,
361 };
362 }
363 if (ieee_exponent == ((@as(u32, 1) << exponent_bits) - 1)) {
364 return .{
365 .mantissa = if (explicit_leading_bit) ieee_mantissa & ((@as(u128, 1) << (mantissa_bits - 1)) - 1) else ieee_mantissa,
366 .exponent = 0x7fffffff,
367 .sign = ieee_sign,
368 };
369 }
370
371 var e2: i32 = undefined;
372 var m2: u128 = undefined;
373 if (explicit_leading_bit) {
374 if (ieee_exponent == 0) {
375 e2 = 1 - cast_i32(bias) - cast_i32(mantissa_bits) + 1 - 2;
376 } else {
377 e2 = cast_i32(ieee_exponent) - cast_i32(bias) - cast_i32(mantissa_bits) + 1 - 2;
378 }
379 m2 = ieee_mantissa;
380 } else {
381 if (ieee_exponent == 0) {
382 e2 = 1 - cast_i32(bias) - cast_i32(mantissa_bits) - 2;
383 m2 = ieee_mantissa;
384 } else {
385 e2 = cast_i32(ieee_exponent) - cast_i32(bias) - cast_i32(mantissa_bits) - 2;
386 m2 = (@as(u128, 1) << mantissa_bits) | ieee_mantissa;
387 }
388 }
389 const even = (m2 & 1) == 0;
390 const accept_bounds = even;
391
392 // Step 2: Determine the interval of legal decimal representations.
393 const mv = 4 * m2;
394 const mm_shift: u1 = @intFromBool((ieee_mantissa != if (explicit_leading_bit) (@as(u128, 1) << (mantissa_bits - 1)) else 0) or (ieee_exponent == 0));
395
396 // Step 3: Convert to a decimal power base using 128-bit arithmetic.
397 var vr: u128 = undefined;
398 var vp: u128 = undefined;
399 var vm: u128 = undefined;
400 var e10: i32 = undefined;
401 var vm_is_trailing_zeros = false;
402 var vr_is_trailing_zeros = false;
403 if (e2 >= 0) {
404 const q: u32 = log10Pow2(@intCast(e2)) - @intFromBool(e2 > 3);
405 e10 = cast_i32(q);
406 const k: i32 = @intCast(FLOAT_128_POW5_INV_BITCOUNT + pow5Bits(q) - 1);
407 const i: u32 = @intCast(-e2 + cast_i32(q) + k);
408
409 const pow5 = computeInvPow5(q);
410 vr = mulShift(4 * m2, &pow5, i);
411 vp = mulShift(4 * m2 + 2, &pow5, i);
412 vm = mulShift(4 * m2 - 1 - mm_shift, &pow5, i);
413
414 if (q <= 55) {
415 if (mv % 5 == 0) {
416 vr_is_trailing_zeros = multipleOfPowerOf5(mv, q -% 1);
417 } else if (accept_bounds) {
418 vm_is_trailing_zeros = multipleOfPowerOf5(mv - 1 - mm_shift, q);
419 } else {
420 vp -= @intFromBool(multipleOfPowerOf5(mv + 2, q));
421 }
422 }
423 } else {
424 const q: u32 = log10Pow5(@intCast(-e2)) - @intFromBool(-e2 > 1);
425 e10 = cast_i32(q) + e2;
426 const i: i32 = -e2 - cast_i32(q);
427 const k: i32 = cast_i32(pow5Bits(@intCast(i))) - FLOAT_128_POW5_BITCOUNT;
428 const j: u32 = @intCast(cast_i32(q) - k);
429
430 const pow5 = computePow5(@intCast(i));
431 vr = mulShift(4 * m2, &pow5, j);
432 vp = mulShift(4 * m2 + 2, &pow5, j);
433 vm = mulShift(4 * m2 - 1 - mm_shift, &pow5, j);
434
435 if (q <= 1) {
436 vr_is_trailing_zeros = true;
437 if (accept_bounds) {
438 vm_is_trailing_zeros = mm_shift == 1;
439 } else {
440 vp -= 1;
441 }
442 } else if (q < 127) {
443 vr_is_trailing_zeros = multipleOfPowerOf2(mv, q - 1);
444 }
445 }
446
447 // Step 4: Find the shortest decimal representation in the interval of legal representations.
448 var removed: u32 = 0;
449 var last_removed_digit: u8 = 0;
450
451 while (vp / 10 > vm / 10) {
452 vm_is_trailing_zeros = vm_is_trailing_zeros and vm % 10 == 0;
453 vr_is_trailing_zeros = vr_is_trailing_zeros and last_removed_digit == 0;
454 last_removed_digit = @intCast(vr % 10);
455 vr /= 10;
456 vp /= 10;
457 vm /= 10;
458 removed += 1;
459 }
460
461 if (vm_is_trailing_zeros) {
462 while (vm % 10 == 0) {
463 vr_is_trailing_zeros = vr_is_trailing_zeros and last_removed_digit == 0;
464 last_removed_digit = @intCast(vr % 10);
465 vr /= 10;
466 vp /= 10;
467 vm /= 10;
468 removed += 1;
469 }
470 }
471
472 if (vr_is_trailing_zeros and (last_removed_digit == 5) and (vr % 2 == 0)) {
473 last_removed_digit = 4;
474 }
475
476 return .{
477 .mantissa = vr + @intFromBool((vr == vm and (!accept_bounds or !vm_is_trailing_zeros)) or last_removed_digit >= 5),
478 .exponent = e10 + cast_i32(removed),
479 .sign = ieee_sign,
480 };
481}
482
483fn decimalLength(v: u128) u32 {
484 const LARGEST_POW10 = (@as(u128, 5421010862427522170) << 64) | 687399551400673280;
485 var p10 = LARGEST_POW10;
486 var i: u32 = 39;
487 while (i > 0) : (i -= 1) {
488 if (v >= p10) return i;
489 p10 /= 10;
490 }
491 return 1;
492}
493
494// floor(log_10(2^e))
495fn log10Pow2(e: u32) u32 {
496 std.debug.assert(e <= 1 << 15);
497 return @intCast((@as(u64, @intCast(e)) * 169464822037455) >> 49);
498}
499
500// floor(log_10(5^e))
501fn log10Pow5(e: u32) u32 {
502 std.debug.assert(e <= 1 << 15);
503 return @intCast((@as(u64, @intCast(e)) * 196742565691928) >> 48);
504}
505
506// if (e == 0) 1 else ceil(log_2(5^e))
507fn pow5Bits(e: u32) u32 {
508 std.debug.assert(e <= 1 << 15);
509 return @intCast(((@as(u64, @intCast(e)) * 163391164108059) >> 46) + 1);
510}
511
512fn pow5Factor(value_: u128) u32 {
513 var count: u32 = 0;
514 var value = value_;
515 while (value > 0) : ({
516 count += 1;
517 value /= 5;
518 }) {
519 if (value % 5 != 0) return count;
520 }
521 return 0;
522}
523
524fn multipleOfPowerOf5(value: u128, p: u32) bool {
525 return pow5Factor(value) >= p;
526}
527
528fn multipleOfPowerOf2(value: u128, p: u32) bool {
529 return (value & ((@as(u128, 1) << @as(u7, @intCast(p))) - 1)) == 0;
530}
531
532fn computeInvPow5(i: u32) [4]u64 {
533 const base = (i + POW5_TABLE_SIZE - 1) / POW5_TABLE_SIZE;
534 const base2 = base * POW5_TABLE_SIZE;
535 const mul = &GENERIC_POW5_INV_SPLIT[base]; // 1 / 5^base2
536 if (i == base2) {
537 return .{ mul[0] + 1, mul[1], mul[2], mul[3] };
538 } else {
539 const offset = base2 - i;
540 const m = &GENERIC_POW5_TABLE[offset]; // 5^offset
541 const delta = pow5Bits(base2) - pow5Bits(i);
542
543 const shift: u6 = @intCast(2 * (i % 32));
544 const corr: u32 = @intCast(((POW5_INV_ERRORS[i / 32] >> shift) & 3) + 1);
545 return mul_128_256_shift(m, mul, delta, corr);
546 }
547}
548
549fn computePow5(i: u32) [4]u64 {
550 const base = i / POW5_TABLE_SIZE;
551 const base2 = base * POW5_TABLE_SIZE;
552 const mul = &GENERIC_POW5_SPLIT[base];
553 if (i == base2) {
554 return mul.*;
555 } else {
556 const offset = i - base2;
557 const m = &GENERIC_POW5_TABLE[offset];
558 const delta = pow5Bits(i) - pow5Bits(base2);
559
560 const shift: u6 = @intCast(2 * (i % 32));
561 const corr: u32 = @intCast((POW5_ERRORS[i / 32] >> shift) & 3);
562 return mul_128_256_shift(m, mul, delta, corr);
563 }
564}
565
566fn mulShift(m: u128, mul: *const [4]u64, j: u32) u128 {
567 std.debug.assert(j > 128);
568 const a: [2]u64 = .{ @truncate(m), @truncate(m >> 64) };
569 const r = mul_128_256_shift(&a, mul, j, 0);
570 return (@as(u128, r[1]) << 64) | r[0];
571}
572
573fn mul_128_256_shift(a: *const [2]u64, b: *const [4]u64, shift: u32, corr: u32) [4]u64 {
574 std.debug.assert(shift > 0);
575 std.debug.assert(shift < 256);
576
577 const b00 = @as(u128, a[0]) * b[0];
578 const b01 = @as(u128, a[0]) * b[1];
579 const b02 = @as(u128, a[0]) * b[2];
580 const b03 = @as(u128, a[0]) * b[3];
581 const b10 = @as(u128, a[1]) * b[0];
582 const b11 = @as(u128, a[1]) * b[1];
583 const b12 = @as(u128, a[1]) * b[2];
584 const b13 = @as(u128, a[1]) * b[3];
585
586 const s0 = b00;
587 const s1 = b01 +% b10;
588 const c1: u128 = @intFromBool(s1 < b01);
589 const s2 = b02 +% b11;
590 const c2: u128 = @intFromBool(s2 < b02);
591 const s3 = b03 +% b12;
592 const c3: u128 = @intFromBool(s3 < b03);
593
594 const p0 = s0 +% (s1 << 64);
595 const d0: u128 = @intFromBool(p0 < b00);
596 const q1 = s2 +% (s1 >> 64) +% (s3 << 64);
597 const d1: u128 = @intFromBool(q1 < s2);
598 const p1 = q1 +% (c1 << 64) +% d0;
599 const d2: u128 = @intFromBool(p1 < q1);
600 const p2 = b13 +% (s3 >> 64) +% c2 +% (c3 << 64) +% d1 +% d2;
601
602 var r0: u128 = undefined;
603 var r1: u128 = undefined;
604 if (shift < 128) {
605 const cshift: u7 = @intCast(shift);
606 const sshift: u7 = @intCast(128 - shift);
607 r0 = corr +% ((p0 >> cshift) | (p1 << sshift));
608 r1 = ((p1 >> cshift) | (p2 << sshift)) +% @intFromBool(r0 < corr);
609 } else if (shift == 128) {
610 r0 = corr +% p1;
611 r1 = p2 +% @intFromBool(r0 < corr);
612 } else {
613 const ashift: u7 = @intCast(shift - 128);
614 const sshift: u7 = @intCast(256 - shift);
615 r0 = corr +% ((p1 >> ashift) | (p2 << sshift));
616 r1 = (p2 >> ashift) +% @intFromBool(r0 < corr);
617 }
618
619 return .{ @truncate(r0), @truncate(r0 >> 64), @truncate(r1), @truncate(r1 >> 64) };
620}
621
622// zig fmt: off
623//
624// 4.5KiB of tables.
625
626const FLOAT_128_POW5_INV_BITCOUNT = 249;
627const FLOAT_128_POW5_BITCOUNT = 249;
628const POW5_TABLE_SIZE = 56;
629
630const GENERIC_POW5_TABLE: [POW5_TABLE_SIZE][2]u64 = .{
631 .{ 1, 0 },
632 .{ 5, 0 },
633 .{ 25, 0 },
634 .{ 125, 0 },
635 .{ 625, 0 },
636 .{ 3125, 0 },
637 .{ 15625, 0 },
638 .{ 78125, 0 },
639 .{ 390625, 0 },
640 .{ 1953125, 0 },
641 .{ 9765625, 0 },
642 .{ 48828125, 0 },
643 .{ 244140625, 0 },
644 .{ 1220703125, 0 },
645 .{ 6103515625, 0 },
646 .{ 30517578125, 0 },
647 .{ 152587890625, 0 },
648 .{ 762939453125, 0 },
649 .{ 3814697265625, 0 },
650 .{ 19073486328125, 0 },
651 .{ 95367431640625, 0 },
652 .{ 476837158203125, 0 },
653 .{ 2384185791015625, 0 },
654 .{ 11920928955078125, 0 },
655 .{ 59604644775390625, 0 },
656 .{ 298023223876953125, 0 },
657 .{ 1490116119384765625, 0 },
658 .{ 7450580596923828125, 0 },
659 .{ 359414837200037393, 2 },
660 .{ 1797074186000186965, 10 },
661 .{ 8985370930000934825, 50 },
662 .{ 8033366502585570893, 252 },
663 .{ 3273344365508751233, 1262 },
664 .{ 16366721827543756165, 6310 },
665 .{ 8046632842880574361, 31554 },
666 .{ 3339676066983768573, 157772 },
667 .{ 16698380334918842865, 788860 },
668 .{ 9704925379756007861, 3944304 },
669 .{ 11631138751360936073, 19721522 },
670 .{ 2815461535676025517, 98607613 },
671 .{ 14077307678380127585, 493038065 },
672 .{ 15046306170771983077, 2465190328 },
673 .{ 1444554559021708921, 12325951644 },
674 .{ 7222772795108544605, 61629758220 },
675 .{ 17667119901833171409, 308148791101 },
676 .{ 14548623214327650581, 1540743955509 },
677 .{ 17402883850509598057, 7703719777548 },
678 .{ 13227442957709783821, 38518598887744 },
679 .{ 10796982567420264257, 192592994438723 },
680 .{ 17091424689682218053, 962964972193617 },
681 .{ 11670147153572883801, 4814824860968089 },
682 .{ 3010503546735764157, 24074124304840448 },
683 .{ 15052517733678820785, 120370621524202240 },
684 .{ 1475612373555897461, 601853107621011204 },
685 .{ 7378061867779487305, 3009265538105056020 },
686 .{ 18443565265187884909, 15046327690525280101 },
687};
688
689const GENERIC_POW5_SPLIT: [89][4]u64 = .{
690 .{ 0, 0, 0, 72057594037927936 },
691 .{ 0, 5206161169240293376, 4575641699882439235, 73468396926392969 },
692 .{ 3360510775605221349, 6983200512169538081, 4325643253124434363, 74906821675075173 },
693 .{ 11917660854915489451, 9652941469841108803, 946308467778435600, 76373409087490117 },
694 .{ 1994853395185689235, 16102657350889591545, 6847013871814915412, 77868710555449746 },
695 .{ 958415760277438274, 15059347134713823592, 7329070255463483331, 79393288266368765 },
696 .{ 2065144883315240188, 7145278325844925976, 14718454754511147343, 80947715414629833 },
697 .{ 8980391188862868935, 13709057401304208685, 8230434828742694591, 82532576417087045 },
698 .{ 432148644612782575, 7960151582448466064, 12056089168559840552, 84148467132788711 },
699 .{ 484109300864744403, 15010663910730448582, 16824949663447227068, 85795995087002057 },
700 .{ 14793711725276144220, 16494403799991899904, 10145107106505865967, 87475779699624060 },
701 .{ 15427548291869817042, 12330588654550505203, 13980791795114552342, 89188452518064298 },
702 .{ 9979404135116626552, 13477446383271537499, 14459862802511591337, 90934657454687378 },
703 .{ 12385121150303452775, 9097130814231585614, 6523855782339765207, 92715051028904201 },
704 .{ 1822931022538209743, 16062974719797586441, 3619180286173516788, 94530302614003091 },
705 .{ 12318611738248470829, 13330752208259324507, 10986694768744162601, 96381094688813589 },
706 .{ 13684493829640282333, 7674802078297225834, 15208116197624593182, 98268123094297527 },
707 .{ 5408877057066295332, 6470124174091971006, 15112713923117703147, 100192097295163851 },
708 .{ 11407083166564425062, 18189998238742408185, 4337638702446708282, 102153740646605557 },
709 .{ 4112405898036935485, 924624216579956435, 14251108172073737125, 104153790666259019 },
710 .{ 16996739107011444789, 10015944118339042475, 2395188869672266257, 106192999311487969 },
711 .{ 4588314690421337879, 5339991768263654604, 15441007590670620066, 108272133262096356 },
712 .{ 2286159977890359825, 14329706763185060248, 5980012964059367667, 110391974208576409 },
713 .{ 9654767503237031099, 11293544302844823188, 11739932712678287805, 112553319146000238 },
714 .{ 11362964448496095896, 7990659682315657680, 251480263940996374, 114756980673665505 },
715 .{ 1423410421096377129, 14274395557581462179, 16553482793602208894, 117003787300607788 },
716 .{ 2070444190619093137, 11517140404712147401, 11657844572835578076, 119294583757094535 },
717 .{ 7648316884775828921, 15264332483297977688, 247182277434709002, 121630231312217685 },
718 .{ 17410896758132241352, 10923914482914417070, 13976383996795783649, 124011608097704390 },
719 .{ 9542674537907272703, 3079432708831728956, 14235189590642919676, 126439609438067572 },
720 .{ 10364666969937261816, 8464573184892924210, 12758646866025101190, 128915148187220428 },
721 .{ 14720354822146013883, 11480204489231511423, 7449876034836187038, 131439155071681461 },
722 .{ 1692907053653558553, 17835392458598425233, 1754856712536736598, 134012579040499057 },
723 .{ 5620591334531458755, 11361776175667106627, 13350215315297937856, 136636387622027174 },
724 .{ 17455759733928092601, 10362573084069962561, 11246018728801810510, 139311567287686283 },
725 .{ 2465404073814044982, 17694822665274381860, 1509954037718722697, 142039123822846312 },
726 .{ 2152236053329638369, 11202280800589637091, 16388426812920420176, 72410041352485523 },
727 .{ 17319024055671609028, 10944982848661280484, 2457150158022562661, 73827744744583080 },
728 .{ 17511219308535248024, 5122059497846768077, 2089605804219668451, 75273205100637900 },
729 .{ 10082673333144031533, 14429008783411894887, 12842832230171903890, 76746965869337783 },
730 .{ 16196653406315961184, 10260180891682904501, 10537411930446752461, 78249581139456266 },
731 .{ 15084422041749743389, 234835370106753111, 16662517110286225617, 79781615848172976 },
732 .{ 8199644021067702606, 3787318116274991885, 7438130039325743106, 81343645993472659 },
733 .{ 12039493937039359765, 9773822153580393709, 5945428874398357806, 82936258850702722 },
734 .{ 984543865091303961, 7975107621689454830, 6556665988501773347, 84560053193370726 },
735 .{ 9633317878125234244, 16099592426808915028, 9706674539190598200, 86215639518264828 },
736 .{ 6860695058870476186, 4471839111886709592, 7828342285492709568, 87903640274981819 },
737 .{ 14583324717644598331, 4496120889473451238, 5290040788305728466, 89624690099949049 },
738 .{ 18093669366515003715, 12879506572606942994, 18005739787089675377, 91379436055028227 },
739 .{ 17997493966862379937, 14646222655265145582, 10265023312844161858, 93168537870790806 },
740 .{ 12283848109039722318, 11290258077250314935, 9878160025624946825, 94992668194556404 },
741 .{ 8087752761883078164, 5262596608437575693, 11093553063763274413, 96852512843287537 },
742 .{ 15027787746776840781, 12250273651168257752, 9290470558712181914, 98748771061435726 },
743 .{ 15003915578366724489, 2937334162439764327, 5404085603526796602, 100682155783835929 },
744 .{ 5225610465224746757, 14932114897406142027, 2774647558180708010, 102653393903748137 },
745 .{ 17112957703385190360, 12069082008339002412, 3901112447086388439, 104663226546146909 },
746 .{ 4062324464323300238, 3992768146772240329, 15757196565593695724, 106712409346361594 },
747 .{ 5525364615810306701, 11855206026704935156, 11344868740897365300, 108801712734172003 },
748 .{ 9274143661888462646, 4478365862348432381, 18010077872551661771, 110931922223466333 },
749 .{ 12604141221930060148, 8930937759942591500, 9382183116147201338, 113103838707570263 },
750 .{ 14513929377491886653, 1410646149696279084, 587092196850797612, 115318278760358235 },
751 .{ 2226851524999454362, 7717102471110805679, 7187441550995571734, 117576074943260147 },
752 .{ 5527526061344932763, 2347100676188369132, 16976241418824030445, 119878076118278875 },
753 .{ 6088479778147221611, 17669593130014777580, 10991124207197663546, 122225147767136307 },
754 .{ 11107734086759692041, 3391795220306863431, 17233960908859089158, 124618172316667879 },
755 .{ 7913172514655155198, 17726879005381242552, 641069866244011540, 127058049470587962 },
756 .{ 12596991768458713949, 15714785522479904446, 6035972567136116512, 129545696547750811 },
757 .{ 16901996933781815980, 4275085211437148707, 14091642539965169063, 132082048827034281 },
758 .{ 7524574627987869240, 15661204384239316051, 2444526454225712267, 134668059898975949 },
759 .{ 8199251625090479942, 6803282222165044067, 16064817666437851504, 137304702024293857 },
760 .{ 4453256673338111920, 15269922543084434181, 3139961729834750852, 139992966499426682 },
761 .{ 15841763546372731299, 3013174075437671812, 4383755396295695606, 142733864029230733 },
762 .{ 9771896230907310329, 4900659362437687569, 12386126719044266361, 72764212553486967 },
763 .{ 9420455527449565190, 1859606122611023693, 6555040298902684281, 74188850200884818 },
764 .{ 5146105983135678095, 2287300449992174951, 4325371679080264751, 75641380576797959 },
765 .{ 11019359372592553360, 8422686425957443718, 7175176077944048210, 77122349788024458 },
766 .{ 11005742969399620716, 4132174559240043701, 9372258443096612118, 78632314633490790 },
767 .{ 8887589641394725840, 8029899502466543662, 14582206497241572853, 80171842813591127 },
768 .{ 360247523705545899, 12568341805293354211, 14653258284762517866, 81741513143625247 },
769 .{ 12314272731984275834, 4740745023227177044, 6141631472368337539, 83341915771415304 },
770 .{ 441052047733984759, 7940090120939869826, 11750200619921094248, 84973652399183278 },
771 .{ 3436657868127012749, 9187006432149937667, 16389726097323041290, 86637336509772529 },
772 .{ 13490220260784534044, 15339072891382896702, 8846102360835316895, 88333593597298497 },
773 .{ 4125672032094859833, 158347675704003277, 10592598512749774447, 90063061402315272 },
774 .{ 12189928252974395775, 2386931199439295891, 7009030566469913276, 91826390151586454 },
775 .{ 9256479608339282969, 2844900158963599229, 11148388908923225596, 93624242802550437 },
776 .{ 11584393507658707408, 2863659090805147914, 9873421561981063551, 95457295292572042 },
777 .{ 13984297296943171390, 1931468383973130608, 12905719743235082319, 97326236793074198 },
778 .{ 5837045222254987499, 10213498696735864176, 14893951506257020749, 99231769968645227 },
779};
780
781// Unfortunately, the results are sometimes off by one or two. We use an additional
782// lookup table to store those cases and adjust the result.
783const POW5_ERRORS: [156]u64 = .{
784 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x9555596400000000,
785 0x65a6569525565555, 0x4415551445449655, 0x5105015504144541, 0x65a69969a6965964,
786 0x5054955969959656, 0x5105154515554145, 0x4055511051591555, 0x5500514455550115,
787 0x0041140014145515, 0x1005440545511051, 0x0014405450411004, 0x0414440010500000,
788 0x0044000440010040, 0x5551155000004001, 0x4554555454544114, 0x5150045544005441,
789 0x0001111400054501, 0x6550955555554554, 0x1504159645559559, 0x4105055141454545,
790 0x1411541410405454, 0x0415555044545555, 0x0014154115405550, 0x1540055040411445,
791 0x0000000500000000, 0x5644000000000000, 0x1155555591596555, 0x0410440054569565,
792 0x5145100010010005, 0x0555041405500150, 0x4141450455140450, 0x0000000144000140,
793 0x5114004001105410, 0x4444100404005504, 0x0414014410001015, 0x5145055155555015,
794 0x0141041444445540, 0x0000100451541414, 0x4105041104155550, 0x0500501150451145,
795 0x1001050000004114, 0x5551504400141045, 0x5110545410151454, 0x0100001400004040,
796 0x5040010111040000, 0x0140000150541100, 0x4400140400104110, 0x5011014405545004,
797 0x0000000044155440, 0x0000000010000000, 0x1100401444440001, 0x0040401010055111,
798 0x5155155551405454, 0x0444440015514411, 0x0054505054014101, 0x0451015441115511,
799 0x1541411401140551, 0x4155104514445110, 0x4141145450145515, 0x5451445055155050,
800 0x4400515554110054, 0x5111145104501151, 0x565a655455500501, 0x5565555555525955,
801 0x0550511500405695, 0x4415504051054544, 0x6555595965555554, 0x0100915915555655,
802 0x5540001510001001, 0x5450051414000544, 0x1405010555555551, 0x5555515555644155,
803 0x5555055595496555, 0x5451045004415000, 0x5450510144040144, 0x5554155555556455,
804 0x5051555495415555, 0x5555554555555545, 0x0000000010005455, 0x4000005000040000,
805 0x5565555555555954, 0x5554559555555505, 0x9645545495552555, 0x4000400055955564,
806 0x0040000000000001, 0x4004100100000000, 0x5540040440000411, 0x4565555955545644,
807 0x1140659549651556, 0x0100000410010000, 0x5555515400004001, 0x5955545555155255,
808 0x5151055545505556, 0x5051454510554515, 0x0501500050415554, 0x5044154005441005,
809 0x1455445450550455, 0x0010144055144545, 0x0000401100000004, 0x1050145050000010,
810 0x0415004554011540, 0x1000510100151150, 0x0100040400001144, 0x0000000000000000,
811 0x0550004400000100, 0x0151145041451151, 0x0000400400005450, 0x0000100044010004,
812 0x0100054100050040, 0x0504400005410010, 0x4011410445500105, 0x0000404000144411,
813 0x0101504404500000, 0x0000005044400400, 0x0000000014000100, 0x0404440414000000,
814 0x5554100410000140, 0x4555455544505555, 0x5454105055455455, 0x0115454155454015,
815 0x4404110000045100, 0x4400001100101501, 0x6596955956966a94, 0x0040655955665965,
816 0x5554144400100155, 0xa549495401011041, 0x5596555565955555, 0x5569965959549555,
817 0x969565a655555456, 0x0000001000000000, 0x0000000040000140, 0x0000040100000000,
818 0x1415454400000000, 0x5410415411454114, 0x0400040104000154, 0x0504045000000411,
819 0x0000001000000010, 0x5554000000001040, 0x5549155551556595, 0x1455541055515555,
820 0x0510555454554541, 0x9555555555540455, 0x6455456555556465, 0x4524565555654514,
821 0x5554655255559545, 0x9555455441155556, 0x0000000051515555, 0x0010005040000550,
822 0x5044044040000000, 0x1045040440010500, 0x0000400000040000, 0x0000000000000000,
823};
824
825const GENERIC_POW5_INV_SPLIT: [89][4]u64 = .{
826 .{ 0, 0, 0, 144115188075855872 },
827 .{ 1573859546583440065, 2691002611772552616, 6763753280790178510, 141347765182270746 },
828 .{ 12960290449513840412, 12345512957918226762, 18057899791198622765, 138633484706040742 },
829 .{ 7615871757716765416, 9507132263365501332, 4879801712092008245, 135971326161092377 },
830 .{ 7869961150745287587, 5804035291554591636, 8883897266325833928, 133360288657597085 },
831 .{ 2942118023529634767, 15128191429820565086, 10638459445243230718, 130799390525667397 },
832 .{ 14188759758411913794, 5362791266439207815, 8068821289119264054, 128287668946279217 },
833 .{ 7183196927902545212, 1952291723540117099, 12075928209936341512, 125824179589281448 },
834 .{ 5672588001402349748, 17892323620748423487, 9874578446960390364, 123407996258356868 },
835 .{ 4442590541217566325, 4558254706293456445, 10343828952663182727, 121038210542800766 },
836 .{ 3005560928406962566, 2082271027139057888, 13961184524927245081, 118713931475986426 },
837 .{ 13299058168408384786, 17834349496131278595, 9029906103900731664, 116434285200389047 },
838 .{ 5414878118283973035, 13079825470227392078, 17897304791683760280, 114198414639042157 },
839 .{ 14609755883382484834, 14991702445765844156, 3269802549772755411, 112005479173303009 },
840 .{ 15967774957605076027, 2511532636717499923, 16221038267832563171, 109854654326805788 },
841 .{ 9269330061621627145, 3332501053426257392, 16223281189403734630, 107745131455483836 },
842 .{ 16739559299223642282, 1873986623300664530, 6546709159471442872, 105676117443544318 },
843 .{ 17116435360051202055, 1359075105581853924, 2038341371621886470, 103646834405281051 },
844 .{ 17144715798009627550, 3201623802661132408, 9757551605154622431, 101656519392613377 },
845 .{ 17580479792687825857, 6546633380567327312, 15099972427870912398, 99704424108241124 },
846 .{ 9726477118325522902, 14578369026754005435, 11728055595254428803, 97789814624307808 },
847 .{ 134593949518343635, 5715151379816901985, 1660163707976377376, 95911971106466306 },
848 .{ 5515914027713859358, 7124354893273815720, 5548463282858794077, 94070187543243255 },
849 .{ 6188403395862945512, 5681264392632320838, 15417410852121406654, 92263771480600430 },
850 .{ 15908890877468271457, 10398888261125597540, 4817794962769172309, 90492043761593298 },
851 .{ 1413077535082201005, 12675058125384151580, 7731426132303759597, 88754338271028867 },
852 .{ 1486733163972670293, 11369385300195092554, 11610016711694864110, 87050001685026843 },
853 .{ 8788596583757589684, 3978580923851924802, 9255162428306775812, 85378393225389919 },
854 .{ 7203518319660962120, 15044736224407683725, 2488132019818199792, 83738884418690858 },
855 .{ 4004175967662388707, 18236988667757575407, 15613100370957482671, 82130858859985791 },
856 .{ 18371903370586036463, 53497579022921640, 16465963977267203307, 80553711981064899 },
857 .{ 10170778323887491315, 1999668801648976001, 10209763593579456445, 79006850823153334 },
858 .{ 17108131712433974546, 16825784443029944237, 2078700786753338945, 77489693813976938 },
859 .{ 17221789422665858532, 12145427517550446164, 5391414622238668005, 76001670549108934 },
860 .{ 4859588996898795878, 1715798948121313204, 3950858167455137171, 74542221577515387 },
861 .{ 13513469241795711526, 631367850494860526, 10517278915021816160, 73110798191218799 },
862 .{ 11757513142672073111, 2581974932255022228, 17498959383193606459, 143413724438001539 },
863 .{ 14524355192525042817, 5640643347559376447, 1309659274756813016, 140659771648132296 },
864 .{ 2765095348461978538, 11021111021896007722, 3224303603779962366, 137958702611185230 },
865 .{ 12373410389187981037, 13679193545685856195, 11644609038462631561, 135309501808182158 },
866 .{ 12813176257562780151, 3754199046160268020, 9954691079802960722, 132711173221007413 },
867 .{ 17557452279667723458, 3237799193992485824, 17893947919029030695, 130162739957935629 },
868 .{ 14634200999559435155, 4123869946105211004, 6955301747350769239, 127663243886350468 },
869 .{ 2185352760627740240, 2864813346878886844, 13049218671329690184, 125211745272516185 },
870 .{ 6143438674322183002, 10464733336980678750, 6982925169933978309, 122807322428266620 },
871 .{ 1099509117817174576, 10202656147550524081, 754997032816608484, 120449071364478757 },
872 .{ 2410631293559367023, 17407273750261453804, 15307291918933463037, 118136105451200587 },
873 .{ 12224968375134586697, 1664436604907828062, 11506086230137787358, 115867555084305488 },
874 .{ 3495926216898000888, 18392536965197424288, 10992889188570643156, 113642567358547782 },
875 .{ 8744506286256259680, 3966568369496879937, 18342264969761820037, 111460305746896569 },
876 .{ 7689600520560455039, 5254331190877624630, 9628558080573245556, 109319949786027263 },
877 .{ 11862637625618819436, 3456120362318976488, 14690471063106001082, 107220694767852583 },
878 .{ 5697330450030126444, 12424082405392918899, 358204170751754904, 105161751436977040 },
879 .{ 11257457505097373622, 15373192700214208870, 671619062372033814, 103142345693961148 },
880 .{ 16850355018477166700, 1913910419361963966, 4550257919755970531, 101161718304283822 },
881 .{ 9670835567561997011, 10584031339132130638, 3060560222974851757, 99219124612893520 },
882 .{ 7698686577353054710, 11689292838639130817, 11806331021588878241, 97313834264240819 },
883 .{ 12233569599615692137, 3347791226108469959, 10333904326094451110, 95445130927687169 },
884 .{ 13049400362825383933, 17142621313007799680, 3790542585289224168, 93612312028186576 },
885 .{ 12430457242474442072, 5625077542189557960, 14765055286236672238, 91814688482138969 },
886 .{ 4759444137752473128, 2230562561567025078, 4954443037339580076, 90051584438315940 },
887 .{ 7246913525170274758, 8910297835195760709, 4015904029508858381, 88322337023761438 },
888 .{ 12854430245836432067, 8135139748065431455, 11548083631386317976, 86626296094571907 },
889 .{ 4848827254502687803, 4789491250196085625, 3988192420450664125, 84962823991462151 },
890 .{ 7435538409611286684, 904061756819742353, 14598026519493048444, 83331295300025028 },
891 .{ 11042616160352530997, 8948390828345326218, 10052651191118271927, 81731096615594853 },
892 .{ 11059348291563778943, 11696515766184685544, 3783210511290897367, 80161626312626082 },
893 .{ 7020010856491885826, 5025093219346041680, 8960210401638911765, 78622294318500592 },
894 .{ 17732844474490699984, 7820866704994446502, 6088373186798844243, 77112521891678506 },
895 .{ 688278527545590501, 3045610706602776618, 8684243536999567610, 75631741404109150 },
896 .{ 2734573255120657297, 3903146411440697663, 9470794821691856713, 74179396127820347 },
897 .{ 15996457521023071259, 4776627823451271680, 12394856457265744744, 72754940025605801 },
898 .{ 13492065758834518331, 7390517611012222399, 1630485387832860230, 142715675091463768 },
899 .{ 13665021627282055864, 9897834675523659302, 17907668136755296849, 139975126841173266 },
900 .{ 9603773719399446181, 10771916301484339398, 10672699855989487527, 137287204938390542 },
901 .{ 3630218541553511265, 8139010004241080614, 2876479648932814543, 134650898807055963 },
902 .{ 8318835909686377084, 9525369258927993371, 2796120270400437057, 132065217277054270 },
903 .{ 11190003059043290163, 12424345635599592110, 12539346395388933763, 129529188211565064 },
904 .{ 8701968833973242276, 820569587086330727, 2315591597351480110, 127041858141569228 },
905 .{ 5115113890115690487, 16906305245394587826, 9899749468931071388, 124602291907373862 },
906 .{ 15543535488939245974, 10945189844466391399, 3553863472349432246, 122209572307020975 },
907 .{ 7709257252608325038, 1191832167690640880, 15077137020234258537, 119862799751447719 },
908 .{ 7541333244210021737, 9790054727902174575, 5160944773155322014, 117561091926268545 },
909 .{ 12297384708782857832, 1281328873123467374, 4827925254630475769, 115303583460052092 },
910 .{ 13243237906232367265, 15873887428139547641, 3607993172301799599, 113089425598968120 },
911 .{ 11384616453739611114, 15184114243769211033, 13148448124803481057, 110917785887682141 },
912 .{ 17727970963596660683, 1196965221832671990, 14537830463956404138, 108787847856377790 },
913 .{ 17241367586707330931, 8880584684128262874, 11173506540726547818, 106698810713789254 },
914 .{ 7184427196661305643, 14332510582433188173, 14230167953789677901, 104649889046128358 },
915};
916
917const POW5_INV_ERRORS: [154]u64 = .{
918 0x1144155514145504, 0x0000541555401141, 0x0000000000000000, 0x0154454000000000,
919 0x4114105515544440, 0x0001001111500415, 0x4041411410011000, 0x5550114515155014,
920 0x1404100041554551, 0x0515000450404410, 0x5054544401140004, 0x5155501005555105,
921 0x1144141000105515, 0x0541500000500000, 0x1104105540444140, 0x4000015055514110,
922 0x0054010450004005, 0x4155515404100005, 0x5155145045155555, 0x1511555515440558,
923 0x5558544555515555, 0x0000000000000010, 0x5004000000000050, 0x1415510100000010,
924 0x4545555444514500, 0x5155151555555551, 0x1441540144044554, 0x5150104045544400,
925 0x5450545401444040, 0x5554455045501400, 0x4655155555555145, 0x1000010055455055,
926 0x1000004000055004, 0x4455405104000005, 0x4500114504150545, 0x0000000014000000,
927 0x5450000000000000, 0x5514551511445555, 0x4111501040555451, 0x4515445500054444,
928 0x5101500104100441, 0x1545115155545055, 0x0000000000000000, 0x1554000000100000,
929 0x5555545595551555, 0x5555051851455955, 0x5555555555555559, 0x0000400011001555,
930 0x0000004400040000, 0x5455511555554554, 0x5614555544115445, 0x6455156145555155,
931 0x5455855455415455, 0x5515555144555545, 0x0114400000145155, 0x0000051000450511,
932 0x4455154554445100, 0x4554150141544455, 0x65955555559a5965, 0x5555555854559559,
933 0x9569654559616595, 0x1040044040005565, 0x1010010500011044, 0x1554015545154540,
934 0x4440555401545441, 0x1014441450550105, 0x4545400410504145, 0x5015111541040151,
935 0x5145051154000410, 0x1040001044545044, 0x4001400000151410, 0x0540000044040000,
936 0x0510555454411544, 0x0400054054141550, 0x1001041145001100, 0x0000000140000000,
937 0x0000000014100000, 0x1544005454000140, 0x4050055505445145, 0x0011511104504155,
938 0x5505544415045055, 0x1155154445515554, 0x0000000000004555, 0x0000000000000000,
939 0x5101010510400004, 0x1514045044440400, 0x5515519555515555, 0x4554545441555545,
940 0x1551055955551515, 0x0150000011505515, 0x0044005040400000, 0x0004001004010050,
941 0x0000051004450414, 0x0114001101001144, 0x0401000001000001, 0x4500010001000401,
942 0x0004100000005000, 0x0105000441101100, 0x0455455550454540, 0x5404050144105505,
943 0x4101510540555455, 0x1055541411451555, 0x5451445110115505, 0x1154110010101545,
944 0x1145140450054055, 0x5555565415551554, 0x1550559555555555, 0x5555541545045141,
945 0x4555455450500100, 0x5510454545554555, 0x1510140115045455, 0x1001050040111510,
946 0x5555454555555504, 0x9954155545515554, 0x6596656555555555, 0x0140410051555559,
947 0x0011104010001544, 0x965669659a680501, 0x5655a55955556955, 0x4015111014404514,
948 0x1414155554505145, 0x0540040011051404, 0x1010000000015005, 0x0010054050004410,
949 0x5041104014000100, 0x4440010500100001, 0x1155510504545554, 0x0450151545115541,
950 0x4000100400110440, 0x1004440010514440, 0x0000115050450000, 0x0545404455541500,
951 0x1051051555505101, 0x5505144554544144, 0x4550545555515550, 0x0015400450045445,
952 0x4514155400554415, 0x4555055051050151, 0x1511441450001014, 0x4544554510404414,
953 0x4115115545545450, 0x5500541555551555, 0x5550010544155015, 0x0144414045545500,
954 0x4154050001050150, 0x5550511111000145, 0x1114504055000151, 0x5104041101451040,
955 0x0010501401051441, 0x0010501450504401, 0x4554585440044444, 0x5155555951450455,
956 0x0040000400105555, 0x0000000000000001,
957};
958
959// zig fmt: on
960
961fn check(comptime T: type, value: T, comptime expected: []const u8) !void {
962 const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
963
964 var buf: [6000]u8 = undefined;
965 const value_bits: I = @bitCast(value);
966 const s = try format(&buf, value, .{});
967 try std.testing.expectEqualStrings(expected, s);
968
969 if (@bitSizeOf(T) != 80) {
970 const o = try std.fmt.parseFloat(T, s);
971 const o_bits: I = @bitCast(o);
972
973 if (std.math.isNan(value)) {
974 try std.testing.expect(std.math.isNan(o));
975 } else {
976 try std.testing.expectEqual(value_bits, o_bits);
977 }
978 }
979}
980
981test "format f32" {
982 try check(f32, 0.0, "0e0");
983 try check(f32, -0.0, "-0e0");
984 try check(f32, 1.0, "1e0");
985 try check(f32, -1.0, "-1e0");
986 try check(f32, std.math.nan(f32), "nan");
987 try check(f32, std.math.inf(f32), "inf");
988 try check(f32, -std.math.inf(f32), "-inf");
989 try check(f32, 1.1754944e-38, "1.1754944e-38");
990 try check(f32, @bitCast(@as(u32, 0x7f7fffff)), "3.4028235e38");
991 try check(f32, @bitCast(@as(u32, 1)), "1e-45");
992 try check(f32, 3.355445E7, "3.355445e7");
993 try check(f32, 8.999999e9, "9e9");
994 try check(f32, 3.4366717e10, "3.436672e10");
995 try check(f32, 3.0540412e5, "3.0540412e5");
996 try check(f32, 8.0990312e3, "8.0990312e3");
997 try check(f32, 2.4414062e-4, "2.4414062e-4");
998 try check(f32, 2.4414062e-3, "2.4414062e-3");
999 try check(f32, 4.3945312e-3, "4.3945312e-3");
1000 try check(f32, 6.3476562e-3, "6.3476562e-3");
1001 try check(f32, 4.7223665e21, "4.7223665e21");
1002 try check(f32, 8388608.0, "8.388608e6");
1003 try check(f32, 1.6777216e7, "1.6777216e7");
1004 try check(f32, 3.3554436e7, "3.3554436e7");
1005 try check(f32, 6.7131496e7, "6.7131496e7");
1006 try check(f32, 1.9310392e-38, "1.9310392e-38");
1007 try check(f32, -2.47e-43, "-2.47e-43");
1008 try check(f32, 1.993244e-38, "1.993244e-38");
1009 try check(f32, 4103.9003, "4.1039004e3");
1010 try check(f32, 5.3399997e9, "5.3399997e9");
1011 try check(f32, 6.0898e-39, "6.0898e-39");
1012 try check(f32, 0.0010310042, "1.0310042e-3");
1013 try check(f32, 2.8823261e17, "2.882326e17");
1014 try check(f32, 7.038531e-26, "7.038531e-26");
1015 try check(f32, 9.2234038e17, "9.223404e17");
1016 try check(f32, 6.7108872e7, "6.710887e7");
1017 try check(f32, 1.0e-44, "1e-44");
1018 try check(f32, 2.816025e14, "2.816025e14");
1019 try check(f32, 9.223372e18, "9.223372e18");
1020 try check(f32, 1.5846085e29, "1.5846086e29");
1021 try check(f32, 1.1811161e19, "1.1811161e19");
1022 try check(f32, 5.368709e18, "5.368709e18");
1023 try check(f32, 4.6143165e18, "4.6143166e18");
1024 try check(f32, 0.007812537, "7.812537e-3");
1025 try check(f32, 1.4e-45, "1e-45");
1026 try check(f32, 1.18697724e20, "1.18697725e20");
1027 try check(f32, 1.00014165e-36, "1.00014165e-36");
1028 try check(f32, 200.0, "2e2");
1029 try check(f32, 3.3554432e7, "3.3554432e7");
1030
1031 try check(f32, 1.0, "1e0");
1032 try check(f32, 1.2, "1.2e0");
1033 try check(f32, 1.23, "1.23e0");
1034 try check(f32, 1.234, "1.234e0");
1035 try check(f32, 1.2345, "1.2345e0");
1036 try check(f32, 1.23456, "1.23456e0");
1037 try check(f32, 1.234567, "1.234567e0");
1038 try check(f32, 1.2345678, "1.2345678e0");
1039 try check(f32, 1.23456735e-36, "1.23456735e-36");
1040}
1041
1042test "format f64" {
1043 try check(f64, 0.0, "0e0");
1044 try check(f64, -0.0, "-0e0");
1045 try check(f64, 1.0, "1e0");
1046 try check(f64, -1.0, "-1e0");
1047 try check(f64, std.math.nan(f64), "nan");
1048 try check(f64, std.math.inf(f64), "inf");
1049 try check(f64, -std.math.inf(f64), "-inf");
1050 try check(f64, 2.2250738585072014e-308, "2.2250738585072014e-308");
1051 try check(f64, @bitCast(@as(u64, 0x7fefffffffffffff)), "1.7976931348623157e308");
1052 try check(f64, @bitCast(@as(u64, 1)), "5e-324");
1053 try check(f64, 2.98023223876953125e-8, "2.9802322387695312e-8");
1054 try check(f64, -2.109808898695963e16, "-2.109808898695963e16");
1055 try check(f64, 4.940656e-318, "4.940656e-318");
1056 try check(f64, 1.18575755e-316, "1.18575755e-316");
1057 try check(f64, 2.989102097996e-312, "2.989102097996e-312");
1058 try check(f64, 9.0608011534336e15, "9.0608011534336e15");
1059 try check(f64, 4.708356024711512e18, "4.708356024711512e18");
1060 try check(f64, 9.409340012568248e18, "9.409340012568248e18");
1061 try check(f64, 1.2345678, "1.2345678e0");
1062 try check(f64, @bitCast(@as(u64, 0x4830f0cf064dd592)), "5.764607523034235e39");
1063 try check(f64, @bitCast(@as(u64, 0x4840f0cf064dd592)), "1.152921504606847e40");
1064 try check(f64, @bitCast(@as(u64, 0x4850f0cf064dd592)), "2.305843009213694e40");
1065
1066 try check(f64, 1, "1e0");
1067 try check(f64, 1.2, "1.2e0");
1068 try check(f64, 1.23, "1.23e0");
1069 try check(f64, 1.234, "1.234e0");
1070 try check(f64, 1.2345, "1.2345e0");
1071 try check(f64, 1.23456, "1.23456e0");
1072 try check(f64, 1.234567, "1.234567e0");
1073 try check(f64, 1.2345678, "1.2345678e0");
1074 try check(f64, 1.23456789, "1.23456789e0");
1075 try check(f64, 1.234567895, "1.234567895e0");
1076 try check(f64, 1.2345678901, "1.2345678901e0");
1077 try check(f64, 1.23456789012, "1.23456789012e0");
1078 try check(f64, 1.234567890123, "1.234567890123e0");
1079 try check(f64, 1.2345678901234, "1.2345678901234e0");
1080 try check(f64, 1.23456789012345, "1.23456789012345e0");
1081 try check(f64, 1.234567890123456, "1.234567890123456e0");
1082 try check(f64, 1.2345678901234567, "1.2345678901234567e0");
1083
1084 try check(f64, 4.294967294, "4.294967294e0");
1085 try check(f64, 4.294967295, "4.294967295e0");
1086 try check(f64, 4.294967296, "4.294967296e0");
1087 try check(f64, 4.294967297, "4.294967297e0");
1088 try check(f64, 4.294967298, "4.294967298e0");
1089}
1090
1091test "format f80" {
1092 try check(f80, 0.0, "0e0");
1093 try check(f80, -0.0, "-0e0");
1094 try check(f80, 1.0, "1e0");
1095 try check(f80, -1.0, "-1e0");
1096 try check(f80, std.math.nan(f80), "nan");
1097 try check(f80, std.math.inf(f80), "inf");
1098 try check(f80, -std.math.inf(f80), "-inf");
1099
1100 try check(f80, 2.2250738585072014e-308, "2.2250738585072014e-308");
1101 try check(f80, 2.98023223876953125e-8, "2.98023223876953125e-8");
1102 try check(f80, -2.109808898695963e16, "-2.109808898695963e16");
1103 try check(f80, 4.940656e-318, "4.940656e-318");
1104 try check(f80, 1.18575755e-316, "1.18575755e-316");
1105 try check(f80, 2.989102097996e-312, "2.989102097996e-312");
1106 try check(f80, 9.0608011534336e15, "9.0608011534336e15");
1107 try check(f80, 4.708356024711512e18, "4.708356024711512e18");
1108 try check(f80, 9.409340012568248e18, "9.409340012568248e18");
1109 try check(f80, 1.2345678, "1.2345678e0");
1110}
1111
1112test "format f128" {
1113 try check(f128, 0.0, "0e0");
1114 try check(f128, -0.0, "-0e0");
1115 try check(f128, 1.0, "1e0");
1116 try check(f128, -1.0, "-1e0");
1117 try check(f128, std.math.nan(f128), "nan");
1118 try check(f128, std.math.inf(f128), "inf");
1119 try check(f128, -std.math.inf(f128), "-inf");
1120
1121 try check(f128, 2.2250738585072014e-308, "2.2250738585072014e-308");
1122 try check(f128, 2.98023223876953125e-8, "2.98023223876953125e-8");
1123 try check(f128, -2.109808898695963e16, "-2.109808898695963e16");
1124 try check(f128, 4.940656e-318, "4.940656e-318");
1125 try check(f128, 1.18575755e-316, "1.18575755e-316");
1126 try check(f128, 2.989102097996e-312, "2.989102097996e-312");
1127 try check(f128, 9.0608011534336e15, "9.0608011534336e15");
1128 try check(f128, 4.708356024711512e18, "4.708356024711512e18");
1129 try check(f128, 9.409340012568248e18, "9.409340012568248e18");
1130 try check(f128, 1.2345678, "1.2345678e0");
1131}
lib/std/json/dynamic_test.zig+1-1
......@@ -213,7 +213,7 @@ test "Value.jsonStringify" {
213213 \\ true,
214214 \\ 42,
215215 \\ 43,
216 \\ 4.2e+01,
216 \\ 4.2e1,
217217 \\ "weeee",
218218 \\ [
219219 \\ 1,
lib/std/json/stringify_test.zig+6-6
......@@ -74,16 +74,16 @@ fn testBasicWriteStream(w: anytype, slice_stream: anytype) !void {
7474 \\{
7575 \\ "object": {
7676 \\ "one": 1,
77 \\ "two": 2.0e+00
77 \\ "two": 2e0
7878 \\ },
7979 \\ "string": "This is a string",
8080 \\ "array": [
8181 \\ "Another string",
8282 \\ 1,
83 \\ 3.5e+00
83 \\ 3.5e0
8484 \\ ],
8585 \\ "int": 10,
86 \\ "float": 3.5e+00
86 \\ "float": 3.5e0
8787 \\}
8888 ;
8989 try std.testing.expectEqualStrings(expected, result);
......@@ -123,12 +123,12 @@ test "stringify basic types" {
123123 try testStringify("null", @as(?u8, null), .{});
124124 try testStringify("null", @as(?*u32, null), .{});
125125 try testStringify("42", 42, .{});
126 try testStringify("4.2e+01", 42.0, .{});
126 try testStringify("4.2e1", 42.0, .{});
127127 try testStringify("42", @as(u8, 42), .{});
128128 try testStringify("42", @as(u128, 42), .{});
129129 try testStringify("9999999999999999", 9999999999999999, .{});
130 try testStringify("4.2e+01", @as(f32, 42), .{});
131 try testStringify("4.2e+01", @as(f64, 42), .{});
130 try testStringify("4.2e1", @as(f32, 42), .{});
131 try testStringify("4.2e1", @as(f64, 42), .{});
132132 try testStringify("\"ItBroke\"", @as(anyerror, error.ItBroke), .{});
133133 try testStringify("\"ItBroke\"", error.ItBroke, .{});
134134}
src/arch/wasm/CodeGen.zig+5-5
......@@ -2658,19 +2658,19 @@ fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) Inner
26582658 .rem => return func.callIntrinsic("__umodti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
26592659 .shr => return func.callIntrinsic("__lshrti3", &.{ ty.toIntern(), .i32_type }, ty, &.{ lhs, rhs }),
26602660 .shl => return func.callIntrinsic("__ashlti3", &.{ ty.toIntern(), .i32_type }, ty, &.{ lhs, rhs }),
2661 .xor => {
2661 .@"and", .@"or", .xor => {
26622662 const result = try func.allocStack(ty);
26632663 try func.emitWValue(result);
26642664 const lhs_high_bit = try func.load(lhs, Type.u64, 0);
26652665 const rhs_high_bit = try func.load(rhs, Type.u64, 0);
2666 const xor_high_bit = try func.binOp(lhs_high_bit, rhs_high_bit, Type.u64, .xor);
2667 try func.store(.stack, xor_high_bit, Type.u64, result.offset());
2666 const op_high_bit = try func.binOp(lhs_high_bit, rhs_high_bit, Type.u64, op);
2667 try func.store(.stack, op_high_bit, Type.u64, result.offset());
26682668
26692669 try func.emitWValue(result);
26702670 const lhs_low_bit = try func.load(lhs, Type.u64, 8);
26712671 const rhs_low_bit = try func.load(rhs, Type.u64, 8);
2672 const xor_low_bit = try func.binOp(lhs_low_bit, rhs_low_bit, Type.u64, .xor);
2673 try func.store(.stack, xor_low_bit, Type.u64, result.offset() + 8);
2672 const op_low_bit = try func.binOp(lhs_low_bit, rhs_low_bit, Type.u64, op);
2673 try func.store(.stack, op_low_bit, Type.u64, result.offset() + 8);
26742674 return result;
26752675 },
26762676 .add, .sub => {
test/cases/safety/slice sentinel mismatch - floats.zig +1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
44 _ = stack_trace;
5 if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.20000004e+00, found 4.0e+00")) {
5 if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.2e0, found 4e0")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);