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

Implement Number.prototype.toPrecision #349

Closed
HalidOdat opened this issue Apr 26, 2020 · 10 comments · Fixed by #962
Closed

Implement Number.prototype.toPrecision #349

HalidOdat opened this issue Apr 26, 2020 · 10 comments · Fixed by #962
Assignees
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request

Comments

@HalidOdat
Copy link
Member

HalidOdat commented Apr 26, 2020

The toPrecision() method returns a string representing the Number object to the specified precision.

More information:

@HalidOdat HalidOdat added the enhancement New feature or request label Apr 26, 2020
@zanayr
Copy link
Contributor

zanayr commented Jul 1, 2020

I think I can handle this. :)

I assume it'll live in number/mod.rs?

@HalidOdat
Copy link
Member Author

I assume it'll live in number/mod.rs?

Yes. There already is the to_precision function but its not implemented here

@zanayr
Copy link
Contributor

zanayr commented Jul 10, 2020

Hello, I'm finally moving on this, sorry for the delay. I understand what we are trying to do with toPercision, but I have a few questions concerning the ECMA documentation:

  1. In step 9.a, "let e and n..." I'm going to need a resource on this math.. I understand some of it, but I'm not really familiar with range math? If you know of what I can reference to understand it better, I would be grateful!
  2. In step 9.b, "let m be the String..." Does that me something like: '.0001'?
  3. In step 9.c.ii.1, "Let a be the first code unit..." I assume they mean the 0x value for whatever character is first in m?

Thanks! Best,

@zanayr
Copy link
Contributor

zanayr commented Jul 10, 2020

Actually I think I just figured out #1. It's just a fancy way of saying n * 10^(e - p + 1) - x
The other questions still stand, but I think my assumptions are correct with those as well.

Best,

@HalidOdat
Copy link
Member Author

HalidOdat commented Jul 11, 2020

Hi @zanayr

Maybe checking other engines implementation will help:
V8: https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/src/conversions.cc#L1159-L1225
SpiderMonkey: https://searchfox.org/mozilla-central/source/mfbt/double-conversion/double-conversion/double-to-string.cc#296-353

Hope this helps :)

@HalidOdat HalidOdat added the builtins PRs and Issues related to builtins/intrinsics label Jul 11, 2020
@Razican
Copy link
Member

Razican commented Oct 8, 2020

Hello @zanayr, how is this going?

@Razican Razican mentioned this issue Oct 8, 2020
@zanayr
Copy link
Contributor

zanayr commented Oct 8, 2020

Hello @zanayr, how is this going?

Hello @Razican, Apologies I have been extremely busy and this slipped my mind. I think I left off somewhere still trying to figure out the math behind 9a. I don't know if I can figure it out, perhaps I should've picked an easier issue. 😅

@Razican
Copy link
Member

Razican commented Oct 9, 2020

Hello @zanayr, how is this going?

Hello @Razican, Apologies I have been extremely busy and this slipped my mind. I think I left off somewhere still trying to figure out the math behind 9a. I don't know if I can figure it out, perhaps I should've picked an easier issue. sweat_smile

Would you like us to un-assign it from you? Or would you like to create a draft PR to get some feedback / help?

@zanayr
Copy link
Contributor

zanayr commented Oct 10, 2020

Hello @zanayr, how is this going?

Hello @Razican, Apologies I have been extremely busy and this slipped my mind. I think I left off somewhere still trying to figure out the math behind 9a. I don't know if I can figure it out, perhaps I should've picked an easier issue. sweat_smile

Would you like us to un-assign it from you? Or would you like to create a draft PR to get some feedback / help?

I probably should be un-assigned, I don't have the bandwidth to work on it right now, and I didn't really get that far to begin with. Apologies again, as soon as I am more free, I will return for to help on this project.

@NathanRoyer
Copy link
Contributor

Hey ! I'm currently working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants