basvandijk / scientific

Arbitrary-precision floating-point numbers represented using scientific notation
BSD 3-Clause "New" or "Revised" License
73 stars 40 forks source link

change `formatScientific Fixed Nothing` behavior #80

Closed SmartHypercube closed 2 years ago

SmartHypercube commented 2 years ago

In my opinion, currently, formatScientific Fixed Nothing is a little strange and not very useful.

I expect Nothing here means "the same as Just n, with the least n that does not cause precision lost". Thus:

formatScientific Fixed Nothing 100 = formatScientific Fixed (Just 0) 100 = "100"
formatScientific Fixed Nothing 1234 = formatScientific Fixed (Just 0) 1234 = "1234"
formatScientific Fixed Nothing 1234.5678 = formatScientific Fixed (Just 4) 1234.5678 = "1234.5678"
phadej commented 2 years ago

The behaviour is consistent with showFFloat from Numeric in base:

>>> formatScientific Fixed Nothing 100
"100.0"
>>> formatScientific Fixed Nothing 1234.5678
"1234.5678"
>>> formatScientific Fixed Nothing 1234
"1234.0"
>>> formatScientific Fixed (Just 0) 1234
"1234"
>>> showFFloat Nothing 100 ""
"100.0"
>>> showFFloat Nothing 1234.5678 ""
"1234.5678"
>>> showFFloat Nothing 1234 ""
"1234.0"
>>> showFFloat (Just 0) 1234 ""

I don't see a reason to diverge.

SmartHypercube commented 2 years ago

I see. Thanks for pointing this out.

But I do think the behavior I proposed is useful in many places too, and currently there are no such functions exported in Data.Scientific. Some libraries are using the wrong function to do the job (see linked issue above) due to not having the right function available. It would be great if Data.Scientific exports such a function.

SmartHypercube commented 2 years ago

After rethinking this, I believe scientific is good as it is now. No need for changes.