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(stdlib): Number.parseFloat #1288

Merged
merged 11 commits into from
Dec 3, 2022
Merged

feat(stdlib): Number.parseFloat #1288

merged 11 commits into from
Dec 3, 2022

Conversation

jozanza
Copy link
Contributor

@jozanza jozanza commented May 30, 2022

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Read every line of code, understood like 20% but the tests look great. Most of my comments are about license attribution, links, and comment style.

stdlib/runtime/atof/common.gr Show resolved Hide resolved
stdlib/runtime/atof/decimal.gr Show resolved Hide resolved
stdlib/runtime/atof/decimal.gr Outdated Show resolved Hide resolved
stdlib/runtime/atof/decimal.gr Outdated Show resolved Hide resolved
stdlib/runtime/atof/decimal.gr Outdated Show resolved Hide resolved
stdlib/runtime/atof/parse.gr Show resolved Hide resolved
stdlib/runtime/atof/parse.gr Show resolved Hide resolved
stdlib/runtime/atof/parse.gr Outdated Show resolved Hide resolved
stdlib/runtime/atof/slow.gr Show resolved Hide resolved
Comment on lines 67 to 85
/// Parse the significant digits and biased, binary exponent of a float.
///
/// This is a fallback algorithm that uses a big-integer representation
/// of the float, and therefore is considerably slower than faster
/// approximations. However, it will always determine how to round
/// the significant digits to the nearest machine float, allowing
/// use to handle near half-way cases.
///
/// Near half-way cases are halfway between two consecutive machine floats.
/// For example, the float `16777217.0` has a bitwise representation of
/// `100000000000000000000000 1`. Rounding to a single-precision float,
/// the trailing `1` is truncated. Using round-nearest, tie-even, any
/// value above `16777217.0` must be rounded up to `16777218.0`, while
/// any value before or equal to `16777217.0` must be rounded down
/// to `16777216.0`. These near-halfway conversions therefore may require
/// a large number of digits to unambiguously determine how to round.
///
/// The algorithms described here are based on "Processing Long Numbers Quickly",
/// available here: <https://arxiv.org/pdf/2101.11408.pdf#section.11>.
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Drop rust style comments and use a grain block comment

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

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

One minor comment. I admit a lot of the finer details went over my head also (i.e. lemire.gr), but I am reasonably assured that the parsing logic itself and such is correct. It wouldn't hurt to have another team member look it over (cc @marcusroberts and @ospencer), but I'm comfortable approving.

let (==) = WasmI32.eq
let (+) = WasmI32.add
let (-) = WasmI32.sub
// All of the following calls to `trim` are fine because:
Copy link
Member

Choose a reason for hiding this comment

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

@jozanza Maybe this comment should refer more precisely to where the call site is (rather than "the following")?

@ospencer ospencer changed the title parseFloat feat(stdlib): Number.parseFloat Dec 2, 2022
@ospencer ospencer marked this pull request as ready for review December 2, 2022 22:43
Copy link
Member

@marcusroberts marcusroberts left a comment

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 the correctness from the code, but the tests look good.
So cool to see stuff like this written in Grain too!

Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

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

Amazing work @jozanza and @ospencer 🎉 :shipit:

@phated phated merged commit e21f2b1 into main Dec 3, 2022
@phated phated deleted the parse-float branch December 3, 2022 23:46
@github-actions github-actions bot mentioned this pull request Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants