Skip to content

Commit 1f76d49

Browse files
committed
Also fix the e-324 divide by zero
1 parent b98f75c commit 1f76d49

9 files changed

+31
-25
lines changed

stdlib/std.jsonnet

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ limitations under the License.
546546
local exponent = if n__ == 0 then 0 else std.floor(std.log(std.abs(n__)) / std.log(10));
547547
local suff = (if caps then 'E' else 'e')
548548
+ render_int(exponent, 3, 0, false, true, 10, '');
549-
local mantissa = n__ / std.pow(10, exponent);
549+
local mantissa = if exponent == -324 then
550+
// Avoid a rounding error where std.pow(10, -324) is 0
551+
// -324 is the smallest exponent possible.
552+
n__ * 10 / std.pow(10, exponent + 1)
553+
else
554+
n__ / std.pow(10, exponent);
550555
local zp2 = zero_pad - std.length(suff);
551556
render_float_dec(mantissa, zp2, blank, sign, ensure_pt, trailing, prec) + suff;
552557

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RUNTIME ERROR: cannot test equality of functions
2-
std.jsonnet:1308:9-34 function <anonymous>
2+
std.jsonnet:1313:9-34 function <anonymous>
33
error.equality_function.jsonnet:17:1-33
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
RUNTIME ERROR: foobar
22
error.inside_equals_array.jsonnet:18:18-32 thunk <array_element>
3-
std.jsonnet:1288:29-33 thunk <b>
4-
std.jsonnet:1288:21-33 function <anonymous>
5-
std.jsonnet:1288:21-33 function <aux>
6-
std.jsonnet:1291:15-31 function <anonymous>
7-
std.jsonnet:1292:11-23
3+
std.jsonnet:1293:29-33 thunk <b>
4+
std.jsonnet:1293:21-33 function <anonymous>
5+
std.jsonnet:1293:21-33 function <aux>
6+
std.jsonnet:1296:15-31 function <anonymous>
7+
std.jsonnet:1297:11-23
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
RUNTIME ERROR: foobar
22
error.inside_equals_object.jsonnet:18:22-36 object <b>
3-
std.jsonnet:1302:50-54 thunk <b>
4-
std.jsonnet:1302:42-54 function <anonymous>
5-
std.jsonnet:1302:42-54 function <aux>
6-
std.jsonnet:1305:15-31 function <anonymous>
7-
std.jsonnet:1306:11-23
3+
std.jsonnet:1307:50-54 thunk <b>
4+
std.jsonnet:1307:42-54 function <anonymous>
5+
std.jsonnet:1307:42-54 function <aux>
6+
std.jsonnet:1310:15-31 function <anonymous>
7+
std.jsonnet:1311:11-23
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Object assertion failed.
22
error.invariant.equality.jsonnet:17:10-15 thunk <object_assert>
3-
std.jsonnet:1302:42-46 thunk <a>
4-
std.jsonnet:1302:42-54 function <anonymous>
5-
std.jsonnet:1302:42-54 function <anonymous>
6-
std.jsonnet:1306:11-23
3+
std.jsonnet:1307:42-46 thunk <a>
4+
std.jsonnet:1307:42-54 function <anonymous>
5+
std.jsonnet:1307:42-54 function <anonymous>
6+
std.jsonnet:1311:11-23
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Object assertion failed.
22
error.obj_assert.fail1.jsonnet:20:23-29 thunk <object_assert>
3-
std.jsonnet:1302:42-46 thunk <a>
4-
std.jsonnet:1302:42-54 function <anonymous>
5-
std.jsonnet:1302:42-54 function <anonymous>
6-
std.jsonnet:1306:11-23
3+
std.jsonnet:1307:42-46 thunk <a>
4+
std.jsonnet:1307:42-54 function <anonymous>
5+
std.jsonnet:1307:42-54 function <anonymous>
6+
std.jsonnet:1311:11-23
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: foo was not equal to bar
22
error.obj_assert.fail2.jsonnet:20:32-65 thunk <object_assert>
3-
std.jsonnet:1302:42-46 thunk <a>
4-
std.jsonnet:1302:42-54 function <anonymous>
5-
std.jsonnet:1302:42-54 function <anonymous>
6-
std.jsonnet:1306:11-23
3+
std.jsonnet:1307:42-46 thunk <a>
4+
std.jsonnet:1307:42-54 function <anonymous>
5+
std.jsonnet:1307:42-54 function <anonymous>
6+
std.jsonnet:1311:11-23
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RUNTIME ERROR: Assertion failed. 1 != 2
2-
std.jsonnet:782:7-50 function <anonymous>
2+
std.jsonnet:787:7-50 function <anonymous>
33
error.sanity.jsonnet:17:1-22

test_suite/format.jsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ std.assertEqual(std.format('thing-%#-8.4X', [910.3]), 'thing-0X038E ') &&
135135
// e
136136
std.assertEqual(std.format('%e', [910]), '9.100000e+02') &&
137137
std.assertEqual(std.format('%e', [0]), '0.000000e+00') &&
138+
std.assertEqual(std.format('%e', [3.94066e-324]), '5.000000e-324') &&
138139
std.assertEqual(std.format('%.0le', [910]), '9e+02') &&
139140
std.assertEqual(std.format('%.0le', [0]), '0e+00') &&
140141
std.assertEqual(std.format('%#e', [-910]), '-9.100000e+02') &&

0 commit comments

Comments
 (0)