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

Smarter number(float) buffer #1

Open
fengb opened this issue Dec 8, 2021 · 0 comments
Open

Smarter number(float) buffer #1

fengb opened this issue Dec 8, 2021 · 0 comments

Comments

@fengb
Copy link
Owner

fengb commented Dec 8, 2021

The code currently handles floats by using a 4096 buffer space. We can do better:

  • There are 2 main pieces to floats: mantissa + exponent. Both are known to be limited.
  • Max length should be max digits of mantissa + max digits of exponent + formatting flags

Thoughts on a limiting parser:

  1. Fill up the buffer until mantissa is full
  2. If mantissa is full, don't append into buffer. If we didn't see a decimal, keep accruing the digit overflow; this is going to append to the actual exponents.
  3. If we find e, treat the next set of digits as exponents.
  4. Toss this result weird monstrosity result into parseFloat

I believe parseFloat should handle all of these edge cases already, in which case it could possibly be adapted to understand a reader instead of just strings. So maybe we could push an update to stdlib.

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

No branches or pull requests

1 participant