Skip to content

Commit 8cc8631

Browse files
committed
Runtime: better fix of string_of_float
1 parent fcbc99d commit 8cc8631

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

runtime/stdlib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ function caml_format_float (fmt, x) {
606606
s = x.toExponential(prec - 1);
607607
var j = s.indexOf('e');
608608
var exp = +s.slice(j + 1);
609-
if (exp < -4 || x.toFixed(0).length > prec) {
609+
if (exp < -4 || x >= 1e21 || x.toFixed(0).length > prec) {
610610
// remove trailing zeroes
611611
var i = j - 1; while (s.charAt(i) == '0') i--;
612612
if (s.charAt(i) == '.') i--;
@@ -619,7 +619,7 @@ function caml_format_float (fmt, x) {
619619
var p = prec;
620620
if (exp < 0) { p -= exp + 1; s = x.toFixed(p); }
621621
else while (s = x.toFixed(p), s.length > prec + 1) p--;
622-
if (p && ! (s.indexOf('e') > 0)) {
622+
if (p) {
623623
// remove trailing zeroes
624624
var i = s.length - 1; while (s.charAt(i) == '0') i--;
625625
if (s.charAt(i) == '.') i--;

0 commit comments

Comments
 (0)