Skip to content

Commit

Permalink
runtime(Js.{Int,Float}): port @mel.send externals to use @mel.this (
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Jan 19, 2025
1 parent d212896 commit 850b52f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions jscomp/runtime/js_float.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
type t = float

external _NaN : t = "NaN"

(** The special value "Not a Number"
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN> MDN
Expand Down Expand Up @@ -68,7 +67,8 @@ let _ = Js.Float.isFinite 1234
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite> MDN
*)

external toExponential : ?digits:int -> t -> string = "toExponential"
external toExponential : ?digits:int -> (t[@mel.this]) -> string
= "toExponential"
[@@mel.send]
(** Formats a [float] using exponential (scientific) notation
Expand All @@ -90,7 +90,7 @@ The output will be rounded or padded with zeroes if necessary.
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential> MDN
*)

external toFixed : ?digits:int -> t -> string = "toFixed"
external toFixed : ?digits:int -> (t[@mel.this]) -> string = "toFixed"
[@@mel.send]
(** Formats a [float] using fixed point notation
Expand All @@ -113,7 +113,7 @@ The output will be rounded or padded with zeroes if necessary.
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed> MDN
*)

external toPrecision : ?digits:int -> t -> string = "toPrecision"
external toPrecision : ?digits:int -> (t[@mel.this]) -> string = "toPrecision"
[@@mel.send]
(** Formats a [float] using some fairly arbitrary rules
Expand Down Expand Up @@ -143,7 +143,7 @@ before the decimal point.
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision> MDN
*)

external toString : ?radix:int -> t -> string = "toString"
external toString : ?radix:int -> (t[@mel.this]) -> string = "toString"
[@@mel.send]
(** Formats a [float] as a string
Expand All @@ -166,7 +166,6 @@ value must be in the range \[2, 36\] (inclusive).
*)

external fromString : string -> t = "Number"

(** Parses the given [string] into a [float] using JavaScript semantics
{b Returns} the number as a [float] if successfully parsed, [_NaN] otherwise.
Expand Down
7 changes: 3 additions & 4 deletions jscomp/runtime/js_int.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
(** Provides functions for inspecting and manipulating [int]s *)

type t = int

(** If we use number, we need coerce to int32 by adding `|0`,
otherwise `+0` can be wrong.
Most JS API is float oriented, it may overflow int32 or
comes with [NAN]
*)
(* + conversion*)

external toExponential : ?digits:t -> t -> string = "toExponential"
external toExponential : ?digits:t -> (t[@mel.this]) -> string = "toExponential"
[@@mel.send]
(** Formats an [int] using exponential (scientific) notation
Expand All @@ -55,7 +54,7 @@ The output will be rounded or padded with zeroes if necessary.
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential> MDN
*)

external toPrecision : ?digits:t -> t -> string = "toPrecision"
external toPrecision : ?digits:t -> (t[@mel.this]) -> string = "toPrecision"
[@@mel.send]
(** Formats an [int] using some fairly arbitrary rules
Expand Down Expand Up @@ -83,7 +82,7 @@ point.
@see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision> MDN
*)

external toString : ?radix:t -> t -> string = "toString"
external toString : ?radix:t -> (t[@mel.this]) -> string = "toString"
[@@mel.send]
(** Formats an [int] as a string
Expand Down

0 comments on commit 850b52f

Please sign in to comment.