sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1k stars 40 forks source link

Adaptive number of significant digits #179

Open sharkdp opened 9 months ago

sharkdp commented 9 months ago

or at least: support for high-precision integer computations

for more details, see previous discussion here: https://github.com/sharkdp/insect/issues/54

archisman-panigrahi commented 9 months ago

Given how the code is written right now, is it nontrivial to change the behavior to the following?

Calculate and store variables with high precision (as far as machine precision allows) but show only 6 significant digits

sharkdp commented 9 months ago

Calculate and store variables with high precision (as far as machine precision allows) but show only 6 significant digits

This is what we do already.

philippotto commented 1 week ago

Another example to motivate this issue: I just did my taxes (yay) and used numbat for some simple additions. This simplified output caught me a bit off-guard:

  10000 euro + 0.95 euro

    = 10001 €    [Money]

Especially, when dealing with currencies, it seems intuitive to me to render two digits after the dot (unless it's 0). However, I often omit the units if the calculation only involves a single unit type. Therefore, special casing currencies wouldn't have helped me much. Instead, I would love to see some logic à la "render the result with the same precision that was used in the input".

My suggestion probably over-simplifies things, but maybe it's still somehow helpful.