PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.59k stars 70 forks source link

Precision? #56

Open TethysSvensson opened 2 years ago

TethysSvensson commented 2 years ago

First of all: Extremely cool project! (Found you on reddit)

I am unsure what the --precision flag does. I tried to running kalker --precision 1000, however kalker did not output what I expected it to. Perhaps the flag is for internal precision only?

My session:

>> x=0.00000000001
>> x
0
>> x * 10
10^-10 ≈ 0

Perhaps this is an error on my part, but I would not have expected kalker to ever show me an exact 0 when the value is in fact non-zero, no matter which precision is chosen.

Additionally I would expect it to be able to output numbers to higher precision thatn 10^-10. That's much lower than even the range of an f32.

PaddiM8 commented 2 years ago

Ah yes. The precision flag used to do what you would expect it to do. However, once the web version was made, less focus was put on precision, since the big float library doesn't support WebAssembly. This was supposed to be temporary, while trying to find an appropriate library for big floats with WebAssembly support, but since I haven't been able to find one, this should probably be fixed now.

PaddiM8 commented 2 years ago

I now made it so that output values are of the same precision as the precision you specify with the flag, if you explicitly choose one. You lose some eye candy, but now if you specifically need high precision, there is an option for that.

When it comes to normal usage, without the precision flag, it gets a bit complicated, due to floating point errors. Kalker gets around this in some situations by assuming a result like 0.000000000072895 is a floating point error rather than an expected result, since floating point errors like this happens very often, while you don't do calculations on tiny numbers like this as often. It's a trade-off, and not one I'm very comfortable with, but I do really value being able to give the user good readable output. Without this, it would start to show confusing results in other places instead, such as:

>> sin(π)
1.2246467991473531773 * 10^-16
>> 0.1 - 0.2
-0.10000000000000000555

Being able to explicitly say you value precision more now makes it a bit more acceptable, but yeah, I'm still not comfortable with any of these two options. Hm...

bokeron2020 commented 2 years ago

I would really love Kalker woulld offer arbitrary precision. Some other calculators do it but they aren't as user-friendly as Kalker. I don't really understand how they deal with that and floating point errors... but I'm not a programmer.