@@ -43,7 +43,7 @@ function caml_int64_bits_of_float(x) {
4343 if ( ! Number . isFinite ( x ) ) {
4444 if ( Number . isNaN ( x ) ) return caml_int64_create_lo_mi_hi ( 1 , 0 , 0x7ff0 ) ;
4545 if ( x > 0 ) return caml_int64_create_lo_mi_hi ( 0 , 0 , 0x7ff0 ) ;
46- else return caml_int64_create_lo_mi_hi ( 0 , 0 , 0xfff0 ) ;
46+ return caml_int64_create_lo_mi_hi ( 0 , 0 , 0xfff0 ) ;
4747 }
4848 const sign =
4949 x === 0 && 1 / x === Number . NEGATIVE_INFINITY
@@ -159,7 +159,7 @@ function caml_int64_float_of_bits(x) {
159159 if ( exp === 2047 ) {
160160 if ( ( lo | mi | ( hi & 0xf ) ) === 0 )
161161 return hi & 0x8000 ? Number . NEGATIVE_INFINITY : Number . POSITIVE_INFINITY ;
162- else return Number . NaN ;
162+ return Number . NaN ;
163163 }
164164 const k = 2 ** - 24 ;
165165 let res = ( lo * k + mi ) * k + ( hi & 0xf ) ;
@@ -178,7 +178,7 @@ function caml_nextafter_float(x, y) {
178178 if ( x === y ) return y ;
179179 if ( x === 0 ) {
180180 if ( y < 0 ) return - ( 2 ** - 1074 ) ;
181- else return 2 ** - 1074 ;
181+ return 2 ** - 1074 ;
182182 }
183183 let bits = caml_int64_bits_of_float ( x ) ;
184184 const one = caml_int64_of_int32 ( 1 ) ;
@@ -340,10 +340,9 @@ function caml_round_float(x) {
340340 if ( x >= 0 ) {
341341 const y = Math . floor ( x ) ;
342342 return x - y >= 0.5 ? y + 1 : y ;
343- } else {
344- const y = Math . ceil ( x ) ;
345- return y - x >= 0.5 ? y - 1 : y ;
346343 }
344+ const y = Math . ceil ( x ) ;
345+ return y - x >= 0.5 ? y - 1 : y ;
347346}
348347//Provides: caml_cbrt_float const
349348function caml_cbrt_float ( x ) {
@@ -496,18 +495,18 @@ function caml_format_float(fmt, x) {
496495 function toFixed ( x , dp ) {
497496 if ( Math . abs ( x ) < 1.0 ) {
498497 return x . toFixed ( dp ) ;
499- } else {
500- let e = Number . parseInt ( x . toString ( ) . split ( "+" ) [ 1 ] ) ;
501- if ( e > 20 ) {
502- e -= 20 ;
503- x /= 10 ** e ;
504- x += new Array ( e + 1 ) . join ( "0" ) ;
505- if ( dp > 0 ) {
506- x = `${ x } .${ new Array ( dp + 1 ) . join ( "0" ) } ` ;
507- }
508- return x ;
509- } else return x . toFixed ( dp ) ;
510498 }
499+ let e = Number . parseInt ( x . toString ( ) . split ( "+" ) [ 1 ] ) ;
500+ if ( e > 20 ) {
501+ e -= 20 ;
502+ x /= 10 ** e ;
503+ x += new Array ( e + 1 ) . join ( "0" ) ;
504+ if ( dp > 0 ) {
505+ x = `${ x } .${ new Array ( dp + 1 ) . join ( "0" ) } ` ;
506+ }
507+ return x ;
508+ }
509+ return x . toFixed ( dp ) ;
511510 }
512511 let s ;
513512 const f = caml_parse_format ( fmt ) ;
@@ -550,19 +549,18 @@ function caml_format_float(fmt, x) {
550549 if ( s . charAt ( i - 3 ) === "e" )
551550 s = `${ s . slice ( 0 , i - 1 ) } 0${ s . slice ( i - 1 ) } ` ;
552551 break ;
553- } else {
554- let p = prec ;
555- if ( exp < 0 ) {
556- p -= exp + 1 ;
557- s = x . toFixed ( p ) ;
558- } else while ( ( ( s = x . toFixed ( p ) ) , s . length > prec + 1 ) ) p -- ;
559- if ( p ) {
560- // remove trailing zeroes
561- let i = s . length - 1 ;
562- while ( s . charAt ( i ) === "0" ) i -- ;
563- if ( s . charAt ( i ) === "." ) i -- ;
564- s = s . slice ( 0 , i + 1 ) ;
565- }
552+ }
553+ let p = prec ;
554+ if ( exp < 0 ) {
555+ p -= exp + 1 ;
556+ s = x . toFixed ( p ) ;
557+ } else while ( ( s = x . toFixed ( p ) ) && s . length > prec + 1 ) p -- ;
558+ if ( p ) {
559+ // remove trailing zeroes
560+ let i = s . length - 1 ;
561+ while ( s . charAt ( i ) === "0" ) i -- ;
562+ if ( s . charAt ( i ) === "." ) i -- ;
563+ s = s . slice ( 0 , i + 1 ) ;
566564 }
567565 break ;
568566 }
0 commit comments