Results 1 to 6 of 6

Thread: command-line calculator for Windows?

  1. #1
    Member Alexander Rhatushnyak's Avatar
    Join Date
    Oct 2007
    Location
    Canada
    Posts
    237
    Thanks
    39
    Thanked 92 Times in 48 Posts

    Question command-line calculator for Windows?

    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

  2. #2
    Member
    Join Date
    Jun 2009
    Location
    Kraków, Poland
    Posts
    1,475
    Thanks
    26
    Thanked 121 Times in 95 Posts
    Java has builtin classes for decimal numbers. That code:
    Code:
    new BigDecimal("128.36").add(new BigDecimal("126.86")).subtract(new BigDecimal("255.22"))
    gives the correct output.

    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.

  3. #3
    Member m^2's Avatar
    Join Date
    Sep 2008
    Location
    Ślůnsk, PL
    Posts
    1,611
    Thanks
    30
    Thanked 65 Times in 47 Posts
    Something called RPNCalc. There are several of them, I picked the first, use it rarely.

  4. #4
    Administrator Shelwien's Avatar
    Join Date
    May 2008
    Location
    Kharkov, Ukraine
    Posts
    3,424
    Thanks
    223
    Thanked 1,053 Times in 565 Posts
    For that I have a script pcalc.bat:
    Code:
    @perl -ne "print eval($_),chr(10);"
    Before I used SEN's console calculator (SEN is the author of hiew), but now there's only a GUI version on his site.

    btw,
    Code:
    C:\VC>pcalc
    128.36+126.86-255.22
    2.8421709430404e-14
    Terminate batch job (Y/N)? y

  5. #5
    Programmer schnaader's Avatar
    Join Date
    May 2008
    Location
    Hessen, Germany
    Posts
    571
    Thanks
    219
    Thanked 205 Times in 97 Posts
    Quote Originally Posted by Alexander Rhatushnyak View Post
    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
    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:

    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
    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.

    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.

  6. #6
    Member Karhunen's Avatar
    Join Date
    Dec 2011
    Location
    USA
    Posts
    91
    Thanks
    2
    Thanked 1 Time in 1 Post
    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

Similar Threads

  1. UCLC (Ultimate Command Line Compressors) Benchmarks
    By osmanturan in forum Data Compression
    Replies: 2
    Last Post: 4th September 2015, 12:30
  2. Replies: 39
    Last Post: 10th April 2014, 23:26
  3. GCC 4.4.1 for Windows
    By Bulat Ziganshin in forum The Off-Topic Lounge
    Replies: 1
    Last Post: 16th January 2010, 00:39
  4. a small plea for the command line compression developers
    By SvenBent in forum Data Compression
    Replies: 2
    Last Post: 14th June 2008, 03:51
  5. DARK - a new BWT-based command-line archiver
    By encode in forum Forum Archive
    Replies: 138
    Last Post: 23rd September 2006, 22:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •