Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib]: fix some Float functions #673

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions jscomp/stdlib/float.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ external rem : float -> float -> float = "caml_fmod_float" "fmod"
[@@unboxed] [@@noalloc]
external fma : float -> float -> float -> float = "caml_fma_float" "caml_fma"
[@@unboxed] [@@noalloc]
#ifdef BS
external abs : float -> float = "abs"[@@mel.val] [@@mel.scope "Math"]
#else
external abs : float -> float = "%absfloat"
#endif

let zero = 0.
let one = 1.
Expand Down Expand Up @@ -57,6 +61,49 @@ type fpclass = Stdlib.fpclass =
| FP_nan
external classify_float : (float [@unboxed]) -> fpclass =
"caml_classify_float" "caml_classify_float_unboxed" [@@noalloc]

#ifdef BS
external pow : float -> float -> float = "pow" [@@mel.val] [@@mel.scope "Math"]
external sqrt : float -> float = "sqrt" [@@mel.val] [@@mel.scope "Math"]
external cbrt : float -> float = "cbrt" [@@mel.val] [@@mel.scope "Math"]
external exp : float -> float = "exp" [@@mel.val][@@mel.scope "Math"]
external exp2 : float -> float = "caml_exp2_float" "caml_exp2"
[@@unboxed] [@@noalloc]
external log : float -> float = "log" [@@mel.val] [@@mel.scope "Math"]
external log10 : float -> float = "log10"[@@mel.val] [@@mel.scope "Math"]
external log2 : float -> float = "caml_log2_float" "caml_log2"
[@@unboxed] [@@noalloc]
external expm1 : float -> float = "caml_expm1_float" "caml_expm1"
[@@unboxed] [@@noalloc]
external log1p : float -> float = "log1p" [@@mel.val] [@@mel.scope "Math"]
external cos : float -> float = "cos" [@@mel.val] [@@mel.scope "Math"]
external sin : float -> float = "sin" [@@mel.val] [@@mel.scope "Math"]
external tan : float -> float = "tan" [@@mel.val] [@@mel.scope "Math"]
external acos : float -> float = "acos" [@@mel.val] [@@mel.scope "Math"]
external asin : float -> float = "asin" [@@mel.val] [@@mel.scope "Math"]
external atan : float -> float = "atan" [@@mel.val] [@@mel.scope "Math"]
external atan2 : float -> float -> float = "atan2" [@@mel.val] [@@mel.scope "Math"]
external hypot : float -> float -> float
= "caml_hypot_float" "caml_hypot" [@@unboxed] [@@noalloc]
external cosh : float -> float = "cosh" [@@mel.val] [@@mel.scope "Math"]
external sinh : float -> float = "sinh" [@@mel.val] [@@mel.scope "Math"]
external tanh : float -> float = "tanh" [@@mel.val] [@@mel.scope "Math"]
external acosh : float -> float = "acosh" [@@mel.val] [@@mel.scope "Math"]
external asinh : float -> float = "asinh" [@@mel.val] [@@mel.scope "Math"]
external atanh : float -> float = "atanh" [@@mel.val] [@@mel.scope "Math"]
external erf : float -> float = "caml_erf_float" "caml_erf"
[@@unboxed] [@@noalloc]
external erfc : float -> float = "caml_erfc_float" "caml_erfc"
[@@unboxed] [@@noalloc]
external trunc : float -> float = "caml_trunc_float" "caml_trunc"
[@@unboxed] [@@noalloc]
external round : float -> float = "caml_round_float" "caml_round"
[@@unboxed] [@@noalloc]
external ceil : float -> float = "caml_ceil_float" "ceil"
[@@unboxed] [@@noalloc]
external floor : float -> float = "caml_floor_float" "floor"
[@@unboxed] [@@noalloc]
#else
external pow : float -> float -> float = "caml_power_float" "pow"
[@@unboxed] [@@noalloc]
external sqrt : float -> float = "caml_sqrt_float" "sqrt"
Expand Down Expand Up @@ -112,6 +159,9 @@ external ceil : float -> float = "caml_ceil_float" "ceil"
[@@unboxed] [@@noalloc]
external floor : float -> float = "caml_floor_float" "floor"
[@@unboxed] [@@noalloc]
#endif



let is_integer x = x = trunc x && is_finite x

Expand Down
84 changes: 84 additions & 0 deletions jscomp/stdlib/float.cppo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ val pred : float -> float
{!next_after}.
@since 4.08 *)

#ifdef BS
external abs : float -> float = "abs"[@@mel.val] [@@mel.scope "Math"]
#else
external abs : float -> float = "%absfloat"
#endif
(** [abs f] returns the absolute value of [f]. *)

val infinity : float
Expand Down Expand Up @@ -213,22 +217,38 @@ external classify_float : (float [@unboxed]) -> fpclass =
(** Return the class of the given floating-point number:
normal, subnormal, zero, infinite, or not a number. *)

#ifdef BS
external pow : float -> float -> float = "pow" [@@mel.val] [@@mel.scope "Math"]
#else
external pow : float -> float -> float = "caml_power_float" "pow"
[@@unboxed] [@@noalloc]
#endif
(** Exponentiation. *)

#ifdef BS
external sqrt : float -> float = "sqrt" [@@mel.val] [@@mel.scope "Math"]
#else
external sqrt : float -> float = "caml_sqrt_float" "sqrt"
[@@unboxed] [@@noalloc]
#endif
(** Square root. *)

#ifdef BS
external cbrt : float -> float = "cbrt" [@@mel.val] [@@mel.scope "Math"]
#else
external cbrt : float -> float = "caml_cbrt_float" "caml_cbrt"
[@@unboxed] [@@noalloc]
#endif
(** Cube root.

@since 4.13
*)

#ifdef BS
external exp : float -> float = "exp" [@@mel.val][@@mel.scope "Math"]
#else
external exp : float -> float = "caml_exp_float" "exp" [@@unboxed] [@@noalloc]
#endif
(** Exponential. *)

external exp2 : float -> float = "caml_exp2_float" "caml_exp2"
Expand All @@ -238,11 +258,19 @@ external exp2 : float -> float = "caml_exp2_float" "caml_exp2"
@since 4.13
*)

#ifdef BS
external log : float -> float = "log" [@@mel.val] [@@mel.scope "Math"]
#else
external log : float -> float = "caml_log_float" "log" [@@unboxed] [@@noalloc]
#endif
(** Natural logarithm. *)

#ifdef BS
external log10 : float -> float = "log10"[@@mel.val] [@@mel.scope "Math"]
#else
external log10 : float -> float = "caml_log10_float" "log10"
[@@unboxed] [@@noalloc]
#endif
(** Base 10 logarithm. *)

external log2 : float -> float = "caml_log2_float" "caml_log2"
Expand All @@ -257,37 +285,69 @@ external expm1 : float -> float = "caml_expm1_float" "caml_expm1"
(** [expm1 x] computes [exp x -. 1.0], giving numerically-accurate results
even if [x] is close to [0.0]. *)

#ifdef BS
external log1p : float -> float = "log1p" [@@mel.val] [@@mel.scope "Math"]
#else
external log1p : float -> float = "caml_log1p_float" "caml_log1p"
[@@unboxed] [@@noalloc]
#endif
(** [log1p x] computes [log(1.0 +. x)] (natural logarithm),
giving numerically-accurate results even if [x] is close to [0.0]. *)

#ifdef BS
external cos : float -> float = "cos" [@@mel.val] [@@mel.scope "Math"]
#else
external cos : float -> float = "caml_cos_float" "cos" [@@unboxed] [@@noalloc]
#endif
(** Cosine. Argument is in radians. *)

#ifdef BS
external sin : float -> float = "sin" [@@mel.val] [@@mel.scope "Math"]
#else
external sin : float -> float = "caml_sin_float" "sin" [@@unboxed] [@@noalloc]
#endif
(** Sine. Argument is in radians. *)

#ifdef BS
external tan : float -> float = "tan" [@@mel.val] [@@mel.scope "Math"]
#else
external tan : float -> float = "caml_tan_float" "tan" [@@unboxed] [@@noalloc]
#endif
(** Tangent. Argument is in radians. *)

#ifdef BS
external acos : float -> float = "acos" [@@mel.val] [@@mel.scope "Math"]
#else
external acos : float -> float = "caml_acos_float" "acos"
[@@unboxed] [@@noalloc]
#endif
(** Arc cosine. The argument must fall within the range [[-1.0, 1.0]].
Result is in radians and is between [0.0] and [pi]. *)

#ifdef BS
external asin : float -> float = "asin" [@@mel.val] [@@mel.scope "Math"]
#else
external asin : float -> float = "caml_asin_float" "asin"
[@@unboxed] [@@noalloc]
#endif
(** Arc sine. The argument must fall within the range [[-1.0, 1.0]].
Result is in radians and is between [-pi/2] and [pi/2]. *)

#ifdef BS
external atan : float -> float = "atan" [@@mel.val] [@@mel.scope "Math"]
#else
external atan : float -> float = "caml_atan_float" "atan"
[@@unboxed] [@@noalloc]
#endif
(** Arc tangent.
Result is in radians and is between [-pi/2] and [pi/2]. *)

#ifdef BS
external atan2 : float -> float -> float = "atan2" [@@mel.val] [@@mel.scope "Math"]
#else
external atan2 : float -> float -> float = "caml_atan2_float" "atan2"
[@@unboxed] [@@noalloc]
#endif
(** [atan2 y x] returns the arc tangent of [y /. x]. The signs of [x]
and [y] are used to determine the quadrant of the result.
Result is in radians and is between [-pi] and [pi]. *)
Expand All @@ -300,38 +360,62 @@ external hypot : float -> float -> float = "caml_hypot_float" "caml_hypot"
to origin. If one of [x] or [y] is infinite, returns [infinity]
even if the other is [nan]. *)

#ifdef BS
external cosh : float -> float = "cosh" [@@mel.val] [@@mel.scope "Math"]
#else
external cosh : float -> float = "caml_cosh_float" "cosh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic cosine. Argument is in radians. *)

#ifdef BS
external sinh : float -> float = "sinh" [@@mel.val] [@@mel.scope "Math"]
#else
external sinh : float -> float = "caml_sinh_float" "sinh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic sine. Argument is in radians. *)

#ifdef BS
external tanh : float -> float = "tanh" [@@mel.val] [@@mel.scope "Math"]
#else
external tanh : float -> float = "caml_tanh_float" "tanh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic tangent. Argument is in radians. *)

#ifdef BS
external acosh : float -> float = "acosh" [@@mel.val] [@@mel.scope "Math"]
#else
external acosh : float -> float = "caml_acosh_float" "caml_acosh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic arc cosine. The argument must fall within the range
[[1.0, inf]].
Result is in radians and is between [0.0] and [inf].

@since 4.13
*)

#ifdef BS
external asinh : float -> float = "asinh" [@@mel.val] [@@mel.scope "Math"]
#else
external asinh : float -> float = "caml_asinh_float" "caml_asinh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic arc sine. The argument and result range over the entire
real line.
Result is in radians.

@since 4.13
*)

#ifdef BS
external atanh : float -> float = "atanh" [@@mel.val] [@@mel.scope "Math"]
#else
external atanh : float -> float = "caml_atanh_float" "caml_atanh"
[@@unboxed] [@@noalloc]
#endif
(** Hyperbolic arc tangent. The argument must fall within the range
[[-1.0, 1.0]].
Result is in radians and ranges over the entire real line.
Expand Down
Loading