| ... | @@ -2,6 +2,7 @@ | ... | @@ -2,6 +2,7 @@ |
| 2 | //! https://dl.acm.org/doi/pdf/10.1145/3360595 | 2 | //! https://dl.acm.org/doi/pdf/10.1145/3360595 |
| 3 | | 3 | |
| 4 | const std = @import("std"); | 4 | const std = @import("std"); |
| | 5 | const expectFmt = std.testing.expectFmt; |
| 5 | | 6 | |
| 6 | const special_exponent = 0x7fffffff; | 7 | const special_exponent = 0x7fffffff; |
| 7 | | 8 | |
| ... | @@ -131,7 +132,7 @@ fn round(f: FloatDecimal128, mode: RoundMode, precision: usize) FloatDecimal128 | ... | @@ -131,7 +132,7 @@ fn round(f: FloatDecimal128, mode: RoundMode, precision: usize) FloatDecimal128 |
| 131 | | 132 | |
| 132 | switch (mode) { | 133 | switch (mode) { |
| 133 | .decimal => { | 134 | .decimal => { |
| 134 | if (f.exponent >= 0) { | 135 | if (f.exponent > 0) { |
| 135 | round_digit = (olength - 1) + precision + @as(usize, @intCast(f.exponent)); | 136 | round_digit = (olength - 1) + precision + @as(usize, @intCast(f.exponent)); |
| 136 | } else { | 137 | } else { |
| 137 | const min_exp_required = @as(usize, @intCast(-f.exponent)); | 138 | const min_exp_required = @as(usize, @intCast(-f.exponent)); |
| ... | @@ -1129,3 +1130,10 @@ test "format f128" { | ... | @@ -1129,3 +1130,10 @@ test "format f128" { |
| 1129 | try check(f128, 9.409340012568248e18, "9.409340012568248e18"); | 1130 | try check(f128, 9.409340012568248e18, "9.409340012568248e18"); |
| 1130 | try check(f128, 1.2345678, "1.2345678e0"); | 1131 | try check(f128, 1.2345678, "1.2345678e0"); |
| 1131 | } | 1132 | } |
| | 1133 | |
| | 1134 | test "format float to decimal with zero precision" { |
| | 1135 | try expectFmt("5", "{d:.0}", .{5}); |
| | 1136 | try expectFmt("6", "{d:.0}", .{6}); |
| | 1137 | try expectFmt("7", "{d:.0}", .{7}); |
| | 1138 | try expectFmt("8", "{d:.0}", .{8}); |
| | 1139 | } |