VPC: Variable Precision Calculator

This software can be redistributed under GNU Lesser General Public License.
Every source code of this software can be obtained through GitHub.
Copylight (c) 2024 Shigeo Kobayashi. All rights reserved.
Japanese

Introduction

VPC(Variable Precision Calculator) is a programmable & functional culculator of arbitrary precision using Bigdecimal. Following example computes the circle ratio(π). You can obtain 100 digits in default. And you can specify '$precision=200' to get 200(or more) effective digits.

VPC(Variable Precision Calculator V2) of Bigdecimal(V11)
  Copyright (c) 2024 by Shigeo Kobayashi. Allrights reserved.

Enter command
>a = pi();
 a =  0.3141592653 5897932384 6264338327 9502884197 1693993751 0582097494 4592307816 4062862089 9862803482 5342117068 E1

>$precision = 200
>b = pi()
 b =  0.3141592653 5897932384 6264338327 9502884197 1693993751 0582097494 4592307816 4062862089 9862803482 5342117067 9821480865 1328230664 7093844609 5505822317 2535940812 8481117450 2841027019 3852110555 9644622948 9549303819 6E1

>c = a-b
 c =  0.1785191348 6717693352 9061553904 4941776827 4640591871 5188825497 1589729806 1478894440 3553770510 4506961804 E-100

On the above eample(details are explained later): If you specify $precision = 1000,then 1000 digits can be obtained(this setting affects arithmetic operations such as + - * / of cource).
Parentheses '(' or ')' can be used for more complexed expressions.

To quit the progrmam,just enter quit or exit.

installation

Windows:
Download all necessary files compressed to the single file 'bigdecimal_win.zip'(contains 32bit 'exe' and 'dll').
And extract all files to any folder prepared for VPC. And just run vpc.exe.
If you place the short cut of vpc.exe on the desk top,select 'vpc.bmp' for VPC icon.
Other OS(LINUX etc):
Download all files including source files from GitHub.
Refer to the contents of the downloaded 'makefile', compile(build) necessary files, and install executables(and others) according to your OS by hand.

Contents: Basics Functions Rounding Rounding methods Iterative calculations Environment settings Input/Outout Special symbols

Basics

VPC features:

Functions

Every functions bellow(except for iterations()) return digits of which count is specified by $precision at least after successful computation.
Function nameDescriptionExampleRemarks
atan(a)computes arctangent of a
c = tan-1(a)
>a=atan(0.5)
 a =  0.4636476090 0080611621 ... 5653E0
|a|<=1
sin(a)/cos(a)computes trigonometric function
>a=sin(1);b=cos(1);c=a*a+b*b
 a =  0.8414709848 0789650665 ... 5435E0
 b =  0.5403023058 6813971740 ... 4357E0
 c =  0.1E1
the argument value must be radian, not degree, and must be small enough.
If the argument(a) is greater than 3.14...,then you must adjust a as a=a-3.14.. before calling sin(a) or cos(a).
exp(a)computes exponentiation of Napier's number(base of natural logarithm:ea).
>a=exp(1)
 a =  0.2718281828 4590452353 ... 4E1
ln(a)computes natural logarithm(base of Napier's number).
>a=ln(0.5);b=exp(a)
 a = -0.6931471805 5994530941 723... 42E0
 b =  0.5E0
0 < a <= 2
pi()computes ratio of a circle's circumference(π).
>a=pi()
 a =  0.3141592653 5897932384 ...068 E1
brackets () are necessary.
sqrt(a)computes square root
a=b1/2
>a=sqrt(5)
 a =  0.2236067977 4997896964 ...275 E1
a >= 0
iterations() returns total number of iteration count done just before.
>a=sqrt(2);b=iterations()
 a =  0.1414213562 3730950488 0168872420 ...7E1
 b =  0.2E2
iterations() <= $max_iterations
Notes:
Function nameDescriptionExampleRemarks
abs(a) computes absolute value of a.
>a=abs(-1)
 a =  0.1E1
power(a,n)computes n power of a
b=power(a,n) => b=an
>a=power(2,-2)
 a =  0.25E0
n must be a positiove or negative integer.
a = power(2,0.5) is an error.
int(a)extracts integer part of a.
>a=int((1/3)*100)
 a =  0.33E2
frac(a) extracts fraction part of a.
>a=frac((1/3)*100)
 a =  0.3333333333 3333333333 ... 33 E0
digits(a)returns number of effective digits of a.
>a=(1/3)*2;b=digits(a)
 a =  0.6666666666 6666666666 ... 666 6667E0
 b =  0.104E3
exponent(a)returns an integer number of exponent of a.
a=0.xxxx*10nexponent(a) returns n.
>a=power(10,3);b=exponent(a)
 a =  0.1E4
 b =  0.4E1

Rounding

Rounding operation is implicitly performed when computation result is stored to any variable. If the computation result has more than $precision digits,then it is rounded by the method specified by $round. Rounding operation can also be done explicitly by calling one of two funtions(trim() or round()) listed bellow.
Function nameDescriptionExample
trim(a,n)trim(a,n) means,rounding operation is done on the (n+1)th digit counted from the left most position of a according to the specification of $round. After rounding, a consists of n digits at most.
>?$round
$round          = 'half_up'

>$format=F

>a=1234.5678
 a =  1234.5678
results of trim() and round() are bellow.
round(a,i) round(a,i) rounds a at the i-th position where i is the relative position counted from the decimal point.
If i>=0,then the degit at (i+1)th position from the decimal point to the right is rounded. The total count of digits after the decimal point will be i at most.
If i<0 then,the i-th digit from the decimal point to the left is rounded. As the result,at least i zeros appear from the decimal point to the left.
>b=trim(a,4);c=round(a,1);d=round(a,-1);e=round(a,0)
 b =  1235
 c =  1234.6
 d =  1230
 e =  1235
Rounding methods:
The list of round methods which can be assigned to $round(default: $round = half_up).
Round methodMeaningExample
upround away from zero.
>$round=up;a=round(-1/3,0)
 a = -0.1E1
downround towards zero(truncate).
>$round=down;a=round(-1/3,0)
 a = -0.0
half_upround up if the digit >= 5 otherwise truncated(default).
>a=round(-2/3,3)
 a = -0.667E0
half_downround up if the digit >= 6 otherwise truncated.
>$round=half_down;a=round(5.5555,3)
 a =  0.5555E1
ceilround towards positive infinity.
>$round=ceil;a=trim(1.2345,3);b=trim(-1.2345,3)
 a =  0.124E1
 b = -0.123E1
floorround towards negative infinity.
>$round=floor;a=trim(1.2345,3);b=trim(-1.2345,3)
 a =  0.123E1
 b = -0.124E1
half_evenround towards the even neighbor(Banker's rounding).
>$round=half_even
>a=trim(2.125,3)
 a =  0.212E1
>a=trim(2.135,3)
 a =  0.214E1

Iterative calculations(I/O) and condition statement

MethodDescriptionExample
repeat n;Statements after 'repeat n' to the line end will be repeated n times. n must be positive integer. Factorial of 10(10!)
>n=0;s=1;repeat 10;n=n+1;s=s*n
>?s
s = 0.36288E7
while a op b;Statements after 'while a op b' to the end of line will be repeated while the condition 'a op b' is satisfied(true). a or b must be a variable or any numerical number. One of a or b must be a variable at least. op can be the one listetd bellow.
  • a > b ..... a is greater than b
  • a < b ..... a is less than b
  • a >= b ... a is greater or equal to b
  • a <= b .... a is less than or equal to b
  • a == b ... a is equal to b
  • a != b .... a is not equal to b
Factorial of 10(10!)
>n=10;s=1;while n>0;s=s*n;n=n-1
>?s
s = 0.36288E7
if a op b;If the condition 'a op b' is satisfied,then all statements to the end of line followed will be executed,otherwise skipped. 'break' can be followed by the 'if' to stop execution followed and exit iteration if it is executing. Factorial of 10(10!)
>n=0;s=1;repeat 100;n=n+1;s=s*n;if n>=10;break
>?s
s = 0.36288E7
load 'file' V1 V2 ... VnOpens 'file', and reads all lines from the file. After reading each one line,numerical values(which VPC can regard as it is a numeric) in the line will be stored to the variables listed from left to right. So every line must contain n numerics at least. Any numeric after n-th position will be ignored. Contents of 'data.txt'
1 a2 b 2 ;;3 4 5 6
'-11' ( 12) - 13;;
21,, 22 ,23

Execution results
>load data.txt a b c;?a;?b;?c
a = 0.1E1
b = 0.2E1
c = 0.3E1
a = -0.11E2
b = 0.12E2
c = -0.13E2
a = 0.21E2
b = 0.22E2
c = 0.23E2

Environment settings

Setting nameDescriptionExample
$format Controls how the numeric number is printed.
Each character of the character string at the right hand of $format will be processed from left to right. >?$format
$format = '10*E q' # Default setting
  • '10':Any integer. Numerical string is divided by the delimitter(' ' or ',' as explained bellow) at every n(10 in this case) characters for readability.
  • '*' :'*','+',or '-'. controls the first character of the number printed. The following character can be given.
    • '*' ... One space ' ' is output for positive number(default). '-' is output for negative number.
    • '-' ... No space is output for positive number. '-' is output for negative number.
    • '+' ... '+' is output for positive number. '-' is output for negative number.

  • 'E' :'E' or 'F'. when 'E'is specified,then number is output as 0.123...E3,where E3 means 103. 'F' means to output number in normal format without power of 10 specification.
  • ' ' :' ' or ','. specify the delimitter of the number string. A space or comma can be specified.
  • 'q' :'q' or 'Q'. when 'Q' is specified, then the numeric string output is quoted by '. 'q' is not.
  • If the same specifications are found,then later specification will be adopted.
    Specifications can be specified separately as follows.
    $format = 5F
    $format = q
>?$format
$format         = '10*E q'  # Default value

>a=123456789012345
 a =  0.1234567890 12345E15

>$format = 5
>?a
 a =  0.12345 67890 12345 E15'

>$format=+
>?a
 a = +0.12345 67890 12345 E15

>$format=,
>?a
 a = +0.12345,67890,12345,E15

>$format=Q
>?a
 a = '+0.12345,67890,12345,E15'

>$format = F;?a
 a = '+12345,67890,12345'

>?$format
$format         = '5+F,Q'

>$format = " "
>?$format
$format         = '5+F Q'

$max_iterationsmaximum number of iteration count for computing sin() cos() ...etc. Default value: 10000
$precision Maximum number of digits that each variable a,b,...z can hold. In case like a=b*c+d,the right hand side of the equation will be performed as many digits as to keep the exact result(computation like 1/3 is a special case ). And finaly rounded when stored to the left hand side variable when the total digits are greater than $precision according to the $round specification. Default value: 100
$roundMethod for the rounding operation. Default value: half_up
$titleAny character string can be specified.Default value: ""
$a,$b,...$y,$z Any character string can be specified. Any comments about each variable may be useful. Default value: ""

Input/Output

I/O statementDescription
read 'file path'Specified file is read and executed. If the file is output by 'write' command,then everything will be restored to the state when the 'write' command is executed.
write 'file path'Every value of variables and environment setting will be output to the specified file. Every thing can be restored by read command to the state when write is executed.

vpc.ini file

Before VPC is running, if you prepare the file vpc.ini at the working directory(usually,the place where vpc.exe is placed),it can be read and executed if you want. This may be convenient if you alway prefer to set $format,$precision,... before actual execution.

vpc.ini can be read or written at any time by following commands.

Special symbols

Special symbols (Infinity and NaN) are used for unrepresentable results for division by zero. The reasult value of division by zero cannnot be represented by any numerical symbol. After division by zero, 'a' will be stored special symbol listed above. Division by zero is itself an error. And referencing to 'a' after the division is also an error. NaN is not a number and never coincident with anything including itself.

+0 and -0
0(zero)can be represented as +0 or -0 (they are actually the same as listed bellow).

  a  = -1*0; ?a  # =>  a = -0
  b  =  1*0; ?b  # =>  b =  0
  c  =  a*b; ?c  # =>  c = -0
  $d = "0 == -0"
  if a==b;   ?$d # => "0 == -0"

Shigeo Kobayashi 2024-3-15