creachadair / imath

Arbitrary precision integer and rational arithmetic library
Other
131 stars 20 forks source link

how to use imcalc.exe #55

Closed zhouxs1023 closed 2 years ago

zhouxs1023 commented 2 years ago

I compile imcalc.c successfully,but I do not how to use imcalc.exe??can you help me? 123

creachadair commented 2 years ago

Hi, @zhouxs1023. The imcalc program is a Reverse Polish Notation (RPN) calculator, so the operators follow their arguments. For example:

echo 2 3 + 4 mul . | ./imcalc
20

The help command lists the various operators the calculator understands:

Operators understood:
abs        x -- |x|
neg        x -- (-x)
+          x y -- (x+y)
add        x y -- (x+y)
-          x y -- (x-y)
sub        x y -- (x-y)
*          x y -- (x*y)
mul        x y -- (x*y)
/          x y -- q r ; x = yq + r, 0 <= r < y
//         x y -- (x div y)
div        x y -- (x div y)
%          x y -- (x mod y)
mod        x y -- (x mod y)
^          x y -- (x^y)
expt       x y -- (x^y)
^^         x y m -- (x^y mod m)
emod       x y m -- (x^y mod m)
sqr        x -- (x*x)
inv        x m -- (1/x mod m)
gcd        x y -- gcd(x, y)
xgcd       x y -- g u v ; g = ux + vy
sqrt       x -- floor(sqrt(x))
root       x y -- floor(x^{1/y}) ; y > 0
<          x y -- (x<y)
>          x y -- (x>y)
<=         x y -- (x<=y)
>=         x y -- (x>=y)
=          x y -- (x=y)
<>         x y -- (x<>y)
inc        x -- (x+1)
dec        x -- (x-1)
!          x -- x!
fact       x -- x!
.          x -- ; print x in current output mode
;          x -- x ; print x in current output mode
?          -- ; print stack
cls        ... -- ; clear stack
$          x --
drop       x --
dup        x -- x x
copy       vn ... v1 v0 n -- vn ... v0 vn ... v0
swap       x y -- y x
rot        a b c -- b c a
pick       ... v2 v1 v0 n -- ... v2 v1 v0 vn
>>         x -- ; save in named variable
<<         -- x ; recall from named variable
clm        -- ; clear memory
??         -- ; print memory
out        r -- ; set output radix to r
bin        -- ; set output format to binary
help       -- ; print help message

The tool is really not meant for serious work, it's just a convenient harness for manually exercising the library.

creachadair commented 2 years ago

I'm closing this issue, but if you still have questions feel free to reopen it with additional comments.