Skip to content

Latest commit

 

History

History
324 lines (229 loc) · 5.37 KB

basic.md

File metadata and controls

324 lines (229 loc) · 5.37 KB

basic

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

add

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

coeff

The value of p0 without the decimal point.

( p0:Decimal -- BigInt )

Example:

Input Stack
12.345 coeff 12345

dec

Pops p0 from the stack and formats it as a Decimal.

( p0:Decimal -- Decimal )
( p0:Float -- Decimal )

Example:

Input Stack
1e3 dec 1000

div

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

div-rem

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

mod

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

mul

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

neg

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

pow

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

rem

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

sign

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

sq

The square of p0.

Alias: square

( p0:BigInt -- BigInt )
( p0:Float -- Float )

Example:

Input Stack
8 sq 64

sqrt

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

sub

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