Skip to content

Commit b98f75c

Browse files
committed
Fix %e handling of 0
1 parent 57719bc commit b98f75c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

stdlib/std.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ limitations under the License.
543543

544544
// Render floating point in scientific form
545545
local render_float_sci(n__, zero_pad, blank, sign, ensure_pt, trailing, caps, prec) =
546-
local exponent = std.floor(std.log(std.abs(n__)) / std.log(10));
546+
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, '');
549549
local mantissa = n__ / std.pow(10, exponent);

test_suite/format.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ std.assertEqual(std.format('thing-%#-8.4X', [910.3]), 'thing-0X038E ') &&
134134

135135
// e
136136
std.assertEqual(std.format('%e', [910]), '9.100000e+02') &&
137+
std.assertEqual(std.format('%e', [0]), '0.000000e+00') &&
137138
std.assertEqual(std.format('%.0le', [910]), '9e+02') &&
139+
std.assertEqual(std.format('%.0le', [0]), '0e+00') &&
138140
std.assertEqual(std.format('%#e', [-910]), '-9.100000e+02') &&
139141
std.assertEqual(std.format('%16e', [910]), ' 9.100000e+02') &&
140142
std.assertEqual(std.format('%016e', [910]), '00009.100000e+02') &&

0 commit comments

Comments
 (0)