Which command-line calculator do you use?
I was using this one for many years, it has a small but annoying bug: for example, the result of
math 128.36+126.86-255.22
is not equal to zero:
2.84217094e-014
Which command-line calculator do you use?
I was using this one for many years, it has a small but annoying bug: for example, the result of
math 128.36+126.86-255.22
is not equal to zero:
2.84217094e-014
This newsgroup is dedicated to image compression:
http://linkedin.com/groups/Image-Compression-3363256
Java has builtin classes for decimal numbers. That code:
gives the correct output.Code:new BigDecimal("128.36").add(new BigDecimal("126.86")).subtract(new BigDecimal("255.22"))
GMP has support for rational numbers, so even writing calculator in C/ C++ shouldn't be a big problem.
WolframAlpha.com and Google.com gives result 0, probably some scientific tools like Matlab, Octave, etc should also give 0.
Last edited by Piotr Tarsa; 14th June 2011 at 23:31.
Something called RPNCalc. There are several of them, I picked the first, use it rarely.
For that I have a script pcalc.bat:
Before I used SEN's console calculator (SEN is the author of hiew), but now there's only a GUI version on his site.Code:@perl -ne "print eval($_),chr(10);"
btw,
Code:C:\VC>pcalc 128.36+126.86-255.22 2.8421709430404e-14 Terminate batch job (Y/N)? y
That's not a bug, but a common error due to the floating point binary representation and its limited accuracy. By the way, you can use a simple workaround to "fix" this in the calculator you're using:
The "exact" function (stored in a MATH.MFC file and so available at later calls of math) rounds everything to 10 decimal places, so the accuracy problems (which are somewhere near the 14th decimal place) will be fixed.Code:C:\>math def:exact(p0) = round(p0 * 10^10) / 10^10 1 C:\>math 128.36+126.86-255.22 2.84217094e-014 C:\>math exact(128.36+126.86-255.22) 0
EDIT: Hm.. seems the "exact" function is only a limited solution, it introduces other errors when using numbers with more than 2 decimal digits:
Code:C:\>math pi 3.14159265 C:\>math exact(pi) 3.14158416
Last edited by schnaader; 15th June 2011 at 14:06.
http://schnaader.info
Damn kids. They're all alike.
Have you tried GNU Calc ? The Win32 files I used were calc-2.11.10.1-dep.zip calc-2.11.10.1-lib.zip calc-2.11.10.1-bin.zip, and to get it to work I needed the files readline5.dll, calc.exe, and calc2.dll. I tried your example and got
# calc 128.36+126.86-255.22
0
# calc 128.36 + 126.86 - 255.22
0
Binaries seem to be from 2005, maybe a more updated version exists. This package seems to also be an AWK-like scripting language as well, but I use regular GNU AWK when I can tolerate imprecision