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

FloatFormat should allow scientific notation with given precision #511

Open
dschrempf opened this issue Apr 27, 2022 · 3 comments
Open

FloatFormat should allow scientific notation with given precision #511

dschrempf opened this issue Apr 27, 2022 · 3 comments

Comments

@dschrempf
Copy link

Hello!

I was wondering if we could get the possibility to format a Float or Double in scientific notation with a given precision (number of decimal places). That is:

scientificFixedPrecision :: Int -> FloatFormat

Further, it would make sense to format Float and Double in standard notation, but with a given number of significant digits.

@sjakobi
Copy link
Member

sjakobi commented Apr 27, 2022

scientificFixedPrecision :: Int -> FloatFormat

There was a brief discussion about this in #365 (comment). Quoting @la-wu:

I don't think it would be particularly hard to implement something for precision for FExponent (we should be able to largely follow what is in base https://github.com/ghc/packages-base/blob/master/GHC/Float.lhs#L602 as I did for the FFixed). But ideally we would move to using a raw buffer-formatter for both FFixed and FExponent with precision so they could be equally efficient there.

Are you interested in working on this? Maybe @la-wu could advise?!


Further, it would make sense to format Float and Double in standard notation, but with a given number of significant digits.

Can you clarify the difference of what you're proposing to the existing standard formatter?

> formatDouble (standard 4) 12.345678
"12.3457"

@dschrempf
Copy link
Author

dschrempf commented Apr 28, 2022

Can you clarify the difference of what you're proposing to the existing standard formatter?

What I meant is the following: Let x=0.0039. One could think of a format formatDouble (significant 1) x which prints 0.004. formatDouble (significant 2) x would print 0.0039, formatDouble (significant 3) x would print 0.00390. Does this make sense?

Are you interested in working on this? Maybe @la-wu could advise?!

I will have a look at the discussion and the linked file, thanks for the references!

@sjakobi
Copy link
Member

sjakobi commented May 3, 2022

What I meant is the following: Let x=0.0039. One could think of a format formatDouble (significant 1) x which prints 0.004. formatDouble (significant 2) x would print 0.0039, formatDouble (significant 3) x would print 0.00390. Does this make sense?

Yes, this makes sense to me. I think it would be best to have a separate issue to track this idea though.

Regarding the name, I think it would be nice to have one that marks this format as a variant of the existing standard format. standardWithSignificantDigits is very long though…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants