Skip to content

Commit

Permalink
feat: improve API of Js.Math (#972)
Browse files Browse the repository at this point in the history
* feat: improve API of Js.Math

* chore: add changelog entry
  • Loading branch information
anmonteiro authored Dec 12, 2023
1 parent 9eadf66 commit 5e03e75
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Unreleased
([#970](https://github.com/melange-re/melange/pull/970))
- BREAKING(runtime): Improve `Js.Float` and change some of its functions to
pipe-last ([#968](https://github.com/melange-re/melange/pull/968))
- BREAKING(runtime): Remove unnecessary `unit` argument from `Js.Math.atan2`
([#972](https://github.com/melange-re/melange/pull/972))

2.2.0 2023-12-05
---------------
Expand Down
12 changes: 4 additions & 8 deletions jscomp/runtime/js_mapper_runtime.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* Copyright (C) 2017 Authors of ReScript
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,18 +17,14 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val raiseWhenNotFound : 'a -> 'a

val fromInt : int -> int array -> int -> int option
(**
[fromInt len array int]
return the mapped [enum]
*)
(** [fromInt len array int] return the mapped [enum] *)

val fromIntAssert : int -> (* len *)
int array -> int -> int
val fromIntAssert : int -> (* len *) int array -> int -> int
17 changes: 11 additions & 6 deletions jscomp/runtime/js_math.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

open Melange_mini_stdlib

Expand Down Expand Up @@ -86,7 +87,7 @@ external atanh : float -> float = "atanh"
[@@mel.scope "Math"]
(** hyperbolic arctangent in radians, can return NaN, ES2015 *)

external atan2 : y:float -> x:float -> unit -> float = "atan2"
external atan2 : y:float -> x:float -> float = "atan2"
[@@mel.scope "Math"]
(** arctangent of the quotient of x and y, mostly... this one's a bit weird *)

Expand All @@ -110,7 +111,8 @@ external ceil_float : float -> float = "ceil"

external clz32 : int -> int = "clz32"
[@@mel.scope "Math"]
(** number of leading zero bits of the argument's 32 bit int representation, ES2015 *)
(** number of leading zero bits of the argument's 32 bit int representation,
ES2015 *)
(* can convert string, float etc. to number *)

external cos : float -> float = "cos"
Expand Down Expand Up @@ -219,7 +221,8 @@ let random_int min max =

external unsafe_round : float -> int = "round"
[@@mel.scope "Math"]
(** rounds to nearest integer, returns a value not representable as [int] if NaN *)
(** rounds to nearest integer, returns a value not representable as [int] if
NaN *)

external round : float -> float = "round"
[@@mel.scope "Math"]
Expand Down Expand Up @@ -254,8 +257,10 @@ external tanh : float -> float = "tanh"

external unsafe_trunc : float -> int = "trunc"
[@@mel.scope "Math"]
(** truncate, ie. remove fractional digits, returns a value not representable as [int] if NaN, ES2015 *)
(** truncate, ie. remove fractional digits, returns a value not representable
as [int] if NaN, ES2015 *)

external trunc : float -> float = "trunc"
[@@mel.scope "Math"]
(** truncate, ie. remove fractional digits, returns a value not representable as [int] if NaN, ES2015 *)
(** truncate, ie. remove fractional digits, returns a value not representable
as [int] if NaN, ES2015 *)
2 changes: 1 addition & 1 deletion jscomp/test/js_math_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let suites = Mt.[
"asinh", (fun _ -> ApproxThreshold(0.001, 0.390, asinh 0.4));
"atan", (fun _ -> ApproxThreshold(0.001, 0.380, atan 0.4));
"atanh", (fun _ -> ApproxThreshold(0.001, 0.423, atanh 0.4));
"atan2", (fun _ -> ApproxThreshold(0.001, 0.588, atan2 ~x:0.6 ~y:0.4 ()));
"atan2", (fun _ -> ApproxThreshold(0.001, 0.588, atan2 ~x:0.6 ~y:0.4));
"cbrt", (fun _ -> Eq(2., cbrt 8.));
"unsafe_ceil_int", (fun _ -> Eq (4, unsafe_ceil_int 3.2));
"ceil_int", (fun _ -> Eq(4, ceil_int 3.2));
Expand Down

0 comments on commit 5e03e75

Please sign in to comment.