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

feat: improve Js.Int and change some functions to pipe-last #966

Merged
merged 6 commits into from
Dec 11, 2023

Conversation

anmonteiro
Copy link
Member

No description provided.

@anmonteiro anmonteiro requested a review from jchavarri December 6, 2023 17:08
Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, there are some refs to toPrecisionWithPrecision that might need updating before merging.

Changes.md Outdated Show resolved Hide resolved
@@ -9,7 +9,7 @@ var suites_0 = [
return {
TAG: /* Eq */0,
_0: "1.23456e+5",
_1: (123456).toExponential()
_1: (123456).toExponential(undefined)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This only happens when no labeled args are passed, right? Hopefully it doesn't have any impact on other JS apis 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. I checked every function to make sure the undefined argument is not an issue.

In the case of Js.Date, for example, we need to keep separate functions, as the undefined argument can make the functions return NaN.

external toPrecisionWithPrecision : int -> digits:int -> string = "toPrecision"
[@@mel.send]
external toPrecision : ?digits:t -> string = "toPrecision"
[@@mel.send.pipe: t]
(** Formats an [int] using some fairly arbitrary rules

{b digits} specifies how many digits should appear in total. The
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe unrelated to the PR, but the part below is a bit unwarranted imo:

for Node it's 21. Why? Who knows

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this. It was pretty easy to check the accepted range by passing it 0:

image

@@ -116,32 +78,16 @@ before the decimal point.
@raise RangeError if digits is not in the range accepted by this function (what do you mean "vague"?)

{[
(* prints "1.2e+8" *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on them, but there are some refs to toPrecisionWithPrecision that are now obsolete:

[toPrecisionWithPrecision] differs from [toFixedWithPrecision] in that the former
will count all digits against the precision, while the latter will count only
the digits after the decimal point. [toPrecisionWithPrecision] will also use
scientific notation if the specified precision is less than the number for digits
before the decimal point.

@anmonteiro anmonteiro force-pushed the anmonteiro/improve-js-int branch from 564b968 to 087e985 Compare December 11, 2023 13:17
anmonteiro and others added 2 commits December 11, 2023 13:20
Co-authored-by: Javier Chávarri <javier.chavarri@gmail.com>
@anmonteiro anmonteiro merged commit cd6e9fa into main Dec 11, 2023
4 checks passed
@anmonteiro anmonteiro deleted the anmonteiro/improve-js-int branch December 11, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants