+ Reply to Thread
Results 1 to 6 of 6

Thread: command-line calculator for Windows?

  1. #1
    Member Alexander Ratushnyak's Avatar
    Join Date
    Oct 2007
    Location
    Canada
    Posts
    119

    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
    Cracov, Poland
    Posts
    711
    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
    Kce, PL
    Posts
    1,037
    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
    1,893
    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
    320
    Quote Originally Posted by Alexander Ratushnyak 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
    54
    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

+ Reply to Thread

Similar Threads

  1. Replies: 35
    Last Post: 20th August 2011, 17:53
  2. GCC 4.4.1 for Windows
    By Bulat Ziganshin in forum Off-Topic
    Replies: 1
    Last Post: 16th January 2010, 01:39
  3. UCLC (Ultimate Command Line Compressors) Benchmarks
    By osmanturan in forum Data Compression
    Replies: 1
    Last Post: 26th February 2009, 04:47
  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