ovk / clcalc

Advanced web-based command-line style calculator
https://clcalc.net
MIT License
40 stars 3 forks source link

Scientific Notation #66

Closed Chris-toph closed 2 years ago

Chris-toph commented 2 years ago

Hello, Thank to provide this nice online calculator. To me one basic feature would be to have the option to display the numbers in scientific notation, i.e. 0.12345678E-27. It is so common, I don't get how it was not included by default. Regards, C.

ovk commented 2 years ago

You can use number literals in scientific notation, for example: 0.12345678E-27. Or did you mean something like an option in settings to display all numbers in this format?

Chris-toph commented 2 years ago

Yes, I mean to display the numbers in scientific notation.

ovk commented 2 years ago

You can use existing MathJS format function to format numbers in desired format, for example:

format(120000, { notation: "exponential" })

(try it here)

Or you could define a simple function to make it less verbose:

toexp(n) = format(n, { notation: "exponential" })

(try it here)

This is obviously not very convenient, so I added new setting Output Number Format that allows to select desired number format:

image

Chris-toph commented 2 years ago

Hello, Thanks for having implement a such of feature. But sorry, to me there is one feature which is not so much meaningful is your setting Precision (Significant Digits) . In general one needs always the maximum precision but it should not be mixed with the display digits. Eg.: if you set the precision to 8 and then calculate pi*1e12 = 3141592700000. To me, your precision setting should be replaced by number of displayed digits as all calculators do! Regards, C.

ovk commented 2 years ago

The precision comes from the underlying decimal.js library and it's not related to how many digits are displayed. All calculators have precision limits, one way or another, as computer memory is finite. Precision limits usually expressed in significant digits or underlying data type size and are not related to how a number will be eventually formatted. So the precision only affects display digits indirectly - it allows to have larger (or smaller) numbers that just take more digits to represent.

But I think I understand your point: it may indeed be beneficial to have high precision but without numbers that take half of the screen when formatted exactly. This can be done now with the format function, but I'll try to add "formatting precision" as a setting later.