Basic calculator
Operation | Description |
---|---|
add, a, + |
Addition |
coeff |
Coefficient |
dec |
Decimal number |
div, d, / |
Division |
div-rem, dr |
Division with remainder |
mod |
Modulus |
mul, m, * |
Multiplication |
neg |
Negation |
pow, **, ^ |
Exponentiation |
rem |
Remainder |
sign |
Sign |
sq, square |
Square |
sqrt, square-root |
Square root |
sub, s, - |
Subtraction |
Adds the value of p1 to p0.
Aliases: a
, +
( p0:BigInt p1:BigInt -- BigInt )
( p0:Decimal p1:Decimal -- Decimal )
( p0:BigFloat p1:BigFloat -- BigFloat )
( p0:Float p1:Float -- Float )
( p0:Rational p1:Rational -- Rational )
( p0:Complex p1:Complex -- Complex )
Example:
Input | Stack |
---|---|
6 |
6 |
2 |
6 | 2 |
a |
8 |
The value of p0 without the decimal point.
( p0:Decimal -- BigInt )
Example:
Input | Stack |
---|---|
12.345 coeff |
12345 |
Pops p0 from the stack and formats it as a Decimal
.
( p0:Decimal -- Decimal )
( p0:Float -- Decimal )
Example:
Input | Stack |
---|---|
1e3 dec |
1000 |
Divides the value of p0 by p1. If p1 is zero, a 'division by zero' error is raised.
Aliases: d
, /
( p0:Decimal p1:Decimal -- Decimal )
( p0:BigFloat p1:BigFloat -- BigFloat )
( p0:Float p1:Float -- Float )
( p0:Rational p1:Rational -- Rational )
( p0:Complex p1:Complex -- Complex )
Example:
Input | Stack |
---|---|
6 |
6 |
2 |
6 | 2 |
d |
3 |
Divides p0 by p1 with the precision p and returns the quotient q and remainder r. The following shows how to divide one dollar with three people which gives a quotient of $0.33 and a remainder of one cent.
Alias: dr
( p0:Decimal p1:Decimal p:Int32 -- r:Decimal q:Decimal )
( p0:BigInt p1:BigInt -- r:Decimal q:Decimal )
Example:
Input | Stack |
---|---|
1.00 3 2 div-rem |
0.01 # remainder | 0.33 |
The modulus when p0 is divided by p1. If p1 is zero, a 'division by zero' error is raised.
( p0:BigInt p1:BigInt -- BigInt )
( p0:Decimal p1:Decimal -- Decimal )
( p0:Float p1:Float -- Float )
Example:
Input | Stack |
---|---|
-7 2 mod |
1 |
Multiplies p0 by p1.
Aliases: m
, *
( p0:BigInt p1:BigInt -- BigInt )
( p0:Decimal p1:Decimal -- Decimal )
( p0:BigFloat p1:BigFloat -- BigFloat )
( p0:Float p1:Float -- Float )
( p0:Rational p1:Rational -- Rational )
( p0:Complex p1:Complex -- Complex )
Example:
Input | Stack |
---|---|
6 |
6 |
2 |
6 | 2 |
m |
12 |
Changes the sign of p0
.
( p0:BigInt -- BigInt )
( p0:Decimal -- Decimal )
( p0:BigFloat -- BigFloat )
( p0:Float -- Float )
( p0:Rational -- Rational )
Example:
Input | Stack |
---|---|
-6 |
-6 |
neg |
6 |
neg |
-6 |
Raises p0 to the power of p1.
Aliases: **
, ^
( p0:BigInt p1:BigInt -- BigInt )
( p0:Float p1:Float -- Float )
( p0:Complex p1:Complex -- Complex )
Example:
Input | Stack |
---|---|
6 |
6 |
2 |
6 | 2 |
pow |
36 |
The remainder when p0 is divided by p1. If p1 is zero, a 'division by zero' error is raised.
( p0:BigInt p1:BigInt -- BigInt )
( p0:Float p1:Float -- Float )
Example:
Input | Stack |
---|---|
-7 |
-7 |
2 |
-7 | 2 |
rem |
-1 |
Returns -1
if p0 is negative, 1
if p0 is positive, or 0
if p0
is zero.
( p0:BigInt -- Int )
( p0:Decimal -- Int )
( p0:BigFloat -- Int )
( p0:Float -- Int )
( p0:Rational -- Int )
Example:
Input | Stack |
---|---|
c -6 sign |
-1 |
c 6 sign |
1 |
c 0 sign |
0 |
The square of p0.
Alias: square
( p0:BigInt -- BigInt )
( p0:Float -- Float )
Example:
Input | Stack |
---|---|
8 sq |
64 |
The square root of p0. If p0 is a positive or zero then a Float is returned. If p0 is negative, a Complex is returned.
Alias: square-root
( p0:Float -- Float )
( p0:BigFloat -- BigFloat )
( p0:Float -- Complex )
( p0:Complex -- Complex )
Example:
Input | Stack |
---|---|
256 |
256 |
sqrt |
16 |
Subtract p1 from p0.
Aliases: s
, -
( p0:BigInt p1:BigInt -- BigInt )
( p0:Decimal p1:Decimal -- Decimal )
( p0:BigFloat p1:BigFloat -- BigFloat )
( p0:Float p1:Float -- Float )
( p0:Rational p1:Rational -- Rational )
( p0:Complex p1:Complex -- Complex )
Example:
Input | Stack |
---|---|
6 |
6 |
2 |
6 | 2 |
s |
4 |