diff --git a/jscomp/others/belt_Float.ml b/jscomp/others/belt_Float.ml index ed9c8fc7eb..c5da4af801 100644 --- a/jscomp/others/belt_Float.ml +++ b/jscomp/others/belt_Float.ml @@ -32,7 +32,7 @@ external toInt: float -> int = "%intoffloat" external fromInt: int -> float = "%identity" -external fromString: string -> float = "parseFloat" [@@bs.val] +external fromString: string -> float = "Number" [@@bs.val] let fromString i = match (fromString i) with diff --git a/jscomp/others/belt_Int.ml b/jscomp/others/belt_Int.ml index c03ce007c1..f6bb92685e 100644 --- a/jscomp/others/belt_Int.ml +++ b/jscomp/others/belt_Int.ml @@ -32,7 +32,7 @@ external toFloat: int -> float = "%identity" external fromFloat: float -> int = "%intoffloat" -external fromString: string -> (_ [@bs.as 10]) -> int = "parseInt" [@@bs.val] +external fromString: string -> (_ [@bs.as 10]) -> int = "Math.trunc" [@@bs.val] let fromString i = match fromString i with diff --git a/jscomp/test/bs_float_test.ml b/jscomp/test/bs_float_test.ml index f6e4efb244..aa780ded57 100644 --- a/jscomp/test/bs_float_test.ml +++ b/jscomp/test/bs_float_test.ml @@ -29,7 +29,16 @@ let () = eq __LOC__ (F.fromString "-1.0") (Some (-1.0)); eq __LOC__ (F.fromString "-1.5") (Some (-1.5)); eq __LOC__ (F.fromString "-1.7") (Some (-1.7)); - eq __LOC__ (F.fromString "not a float") None + eq __LOC__ (F.fromString "17e-1") (Some (1.7)); + eq __LOC__ (F.fromString "-17e-1") (Some (-1.7)); + eq __LOC__ (F.fromString " -17e-1 ") (Some (-1.7)); + eq __LOC__ (F.fromString "0x11") (Some (17.)); + eq __LOC__ (F.fromString "0b11") (Some (3.)); + eq __LOC__ (F.fromString "0o11") (Some (9.)); + eq __LOC__ (F.fromString "") (Some (0.)); + eq __LOC__ (F.fromString "not a float") None; + eq __LOC__ (F.fromString "100.0abcdef") None; + eq __LOC__ (F.fromString "123_456.7") None let () = eq __LOC__ (F.toString 1.0) "1"; diff --git a/jscomp/test/bs_int_test.ml b/jscomp/test/bs_int_test.ml index 0e90c5e0c1..b1cf58f5f0 100644 --- a/jscomp/test/bs_int_test.ml +++ b/jscomp/test/bs_int_test.ml @@ -29,7 +29,16 @@ let () = eq __LOC__ (I.fromString "-1.0") (Some (-1)); eq __LOC__ (I.fromString "-1.5") (Some (-1)); eq __LOC__ (I.fromString "-1.7") (Some (-1)); - eq __LOC__ (I.fromString "not an int") None + eq __LOC__ (I.fromString "17e-1") (Some (1)); + eq __LOC__ (I.fromString "-17e-1") (Some (-1)); + eq __LOC__ (I.fromString " -17e-1 ") (Some (-1)); + eq __LOC__ (I.fromString "0x11") (Some (17)); + eq __LOC__ (I.fromString "0b11") (Some (3)); + eq __LOC__ (I.fromString "0o11") (Some (9)); + eq __LOC__ (I.fromString "") (Some (0)); + eq __LOC__ (I.fromString "not an int") None; + eq __LOC__ (I.fromString "100abcdef") None; + eq __LOC__ (I.fromString "123_456") None let () = eq __LOC__ (I.toString 1) "1";