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
1.25k stars 52 forks source link

More control over display mode / number format #219

Open joshop opened 1 year ago

joshop commented 1 year ago

Hi! I was a huge fan of insect and glad that it's getting even more features, but one thing that I always found missing was a good way to control more specifically how numbers are printed. It's possible I'm missing a builtin function or operator for this in numbat, but both of these feel unhelpful:

>>> 1e14 m

  100000000000000 meter

    = 100000000000000 m    [Length]

>>> 1e-6 m

  0.000001 meter

    = 0.000001 m    [Length]

It would be nice to be able to specify that I want to see 1e14 m or 1e-6 m in this case, or maybe even specify a precision level or a fixed exponent. If you have many quantities in the range 1e-8 m, for instance, you might want to print 1e-9 m as 0.1e-8 m, so it's visually easier to compare. I think the default behavior would stay the same.

sharkdp commented 1 year ago

Thank you for the feedback.

Have you seen https://github.com/sharkdp/numbat/issues/152 (and https://github.com/sharkdp/numbat/issues/179)? I think this feature request is at least related. And it seems like you are asking for this to be (interactively) configurable?

Maybe we could close this and add a comment to #152? What do you think?

joshop commented 1 year ago

That would make sense. I was envisioning an interactive-mode command that can switch from the current default, always using scientific notation (optionally with a certain fixed exponent), or never using scientific notation.

sharkdp commented 9 months ago

Another display mode that was suggested here (#346) would be engineering notation

P1n3appl3 commented 8 months ago

qalculate does something similar to engineering notation, but it uses the SI prefix for the unit instead of writing out the scientific notation which I find generally more useful, for example:

> 0.0000000003F

  0.0000000003 farad = 300 pF

I'd love it if I could set a config option to always "normalize" output like that in numbat, maybe falling back to engineering notation for unit-less calculations. This might be a stretch but doing the same thing for often-mixed units would also be really helpful:

> 4k seconds

  (4 × 1000) seconds = 1 h + 6 min + 40 s

> 1234oz

  1234 ounces = 77 lb + 2 oz

It's possible what I'm looking for is a -> human for all units that I can choose to implicitly apply by default, or setting a default "unit list" (#364) for certain input units.

signalno11 commented 1 month ago

-> human would be a great friendly implementation, but I think it should be more of a macro. For example, -> sci could convert to scientific, -> eng could convert to engineering, and -> si could convert to engineering notation converted to SI prefixes when possible. The user could define in a configuration file when they want which to be used when they ask for -> human