JSI Tip 10283. LONGCALC.EXE freeware can accurately calculate with extremely long numbers.

Jerold Schulman

March 16, 2006

2 Min Read
ITPro Today logo in a gray background | ITPro Today


If you need to calculate with extremely long numbers, up to 65520 base 10 digits, and place it in a folder that is in your path.

LONGCALC.EXE supports the following operators:

 nop tix mls err all stk cls var wln wrs clq tab rdd rze rnd val str neg abs dup inc wrt dec pop srt fac len wts wns shl shr min max cmp mag add and xor oar not imp mul div sub mod swp pow oik dig kio def fed cat exe sbs for if0 no0 ifl nol ifg nog whl ncr hcf lcm #f9 #fn #pi #sd #ds #sm #ms #dw #ws #uf #sa #dt #us #dd #dy #ge #eg ctu INS OUT KEY SCR bas try pip gnv pnv edp cof con hlt

To find out what each operator does:

1. Open a CMD.EXE window.

2. Type LONGCALC and press Enter.

3. Type ?XXX and press Enter, where XXX is an operator.

4. To exit LONGCALC, type hlt and press Enter.

To use LONGCALC.EXE to divide 7,768,489,957,892,578,474,792,094 by 12,280, type:

LONGCALC 7,768,489,957,892,578,474,792,094 12,280 div wrt

The following is displayed:

LONGCALC: www.merlyn.demon.co.uk >= 2005-07-22 compiled with Borland Pascal MSDOS mode.+632,613,188,753,467,302,507

NOTE: LONGCALC.EXE is extremely slow, and should only be used when other methods, like DoMath, won't work.

I have scripted BigCALC.bat to allow you to calculate in a batch.

The syntax for using BigCALC.bat is:

call BigCALC Num1 [Num2] OPR ANS

Where:

Num1 is the first number. If it contains commas, it must be quoted.Num2 is the second number, if required by the operator. If it contains commas, it must be quoted.OPR  is an operator.ANS  is a <a href="https://www.itprotoday.com/article/jsifaq/jsi-tip-5535-how-can-i-cause-a-called-batch-file-to-return-a-call-directed-environment-variable-.aspx">call directed environment variable</a> that will contain the answer.

Example

If you wanted to calculate the square root of 4 times 4 and return the result in environment variable ANS, your batch would contain:

@echo offcall BigCALC 4 4 mul prodcall BigCALC "%prod%" srt ANS@echo %ANS%

BigCALC.bat contains:

@echo offif {%4}
{} @echo Syntax: BigCALC Num1 [Num2] OPR ANS&goto :EOFsetlocalset out="%TEMP%BigCALC_%RANDOM%.TMP"set num1=%1set num1=%num1:"=%if {%4}
{} goto C1set num2=%2set num2=%num2:"=%LONGCALC %num1% %num2% %3 wrt>%out%LONGCALC hlt >nulfor /f "Skip=3 Tokens=*" %%n in ('type %out%^|find /V "RPN"') do ( set ANS=%%n)del /q %out%endlocal&set %4=%ANS%goto :EOF:C1LONGCALC %num1% %2 wrt>%out%LONGCALC hlt >nulfor /f "Skip=3 Tokens=*" %%n in ('type %out%^|find /V "RPN"') do ( set ANS=%%n)del /q %out%endlocal&set %3=%ANS%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like