Numbers

Numbers in StackLang are stored as floating point numbers. Numbers will be displayed to as many decimal places as are significant. When entering a number, any number of ' may be used in a number as a thousands separator, except at the beginning of the number.

The two number constants are commands. That is, they must be evaluated before they turn into a number. Thus, for the most part, they can be used as normal numbers, but they can be quoted.

An EBNF definition of a number is given below.

nonzero-digit = ? Any ASCII arabic numeral ? ;
separator-symbol = "'" ;

processed-digit = {separator-symbol}, digit-symbol, {separator-symbol} ;
digit-string = {processed-digit} ;

sign-symbol = "+" | "-" ;
decimal-point-symbol = "." ;

number = [sign-symbol], digit-string, [decimal point, digit-string] ;

Number-related Commands

Constants

euler : -> Number
Produces Euler's number.

pi : -> Number
Produces π.

Type Predicates

number? : Any -> Boolean
Produces true if given element is a number.

integer? : Any -> Boolean
Produces true if given element is an integer number.

zero? : Any -> Boolean
Produces true if given element is a number equal to zero.

positive? : Any -> Boolean
Produces true if given element is a positive (zero not included) number.

negative? : Any -> Boolean
Produces true if given element is a negative (zero not included) number.

even? : Any -> Boolean
Produces true if given element is an even, integer number.

odd? : Any -> Boolean
Produces true if given element is an odd, integer number.

Type Conversion

number-to-string : Number -> String
Produces the number as it would be printed, but not including a positive sign.

string-to-number : String -> Number
Produces a number from a string as if it were read in from the interpreter. number-to-string is the inverse of string-to-number. Fails with a RuntimeError if string cannot be parsed.

Arithmetic

precision : Number -> Number
Produces the number of decimal places this number is accurate to.

set-precision : Number Number -> Number
Sets the precision of the second number to the first number.

negate : Number -> Number
Produces the negative of the number.

inverse : Number -> Number
Produces one divided by the number.

increment : Number -> Number
Produces the number plus one.

decrement : Number -> Number
Produces the number minus one.

add : Number Number -> Number
Adds two numbers together.

subtract : Number Number -> Number
Subtracts the first number from the second.

multiply : Number Number -> Number
Multiplies two numbers together.

divide : Number Number -> Number
Divides the second number by the first. Will produce a syntax error when dividing by zero.

modulo : Number Number -> Number
Takes the absolute value of both numbers, and subtracts the first from the second until the second is less than the first. Then, the sign of the second is set to the sign of the first.

floor : Number -> Number
Produces the floor of the number (closest integer, rounding down).

ceil : Number -> Number
Produces the ceiling of the number (closest integer, rounding up).

round : Number -> Number
Produces the closest integer, rounding to even.

round* : Number -> Number
Produces the closest integer, rounding up at 0.5.

trunc : Number -> Number
Produces the number, without any decimal digits.

abs : Number -> Number
Produces the absolute value of the number.

sign : Number -> Number
If input is positive, produces 1, else if input is negative, produces -1, else zero.

max : Number Number -> Number
Produces the larger of the two numbers.

min : Number Number -> Number
Produces the smaller of the two numbers.

sqrt : Number -> Number
Produces the square root of the number.

pow : Number Number -> Number
Produces the second number raised to the power of the first number.

exponential : Number -> Number
Produces euler's number to the power of the input.

log : Number Number -> Number
Produces the second number's logarithm, using the first number as the base.

log-e : Number -> Number
Produces the number's natural logarithm.

log-10 : Number -> Number
Produces the number's base-10 logarithm.

log-2 : Number -> Number
Produces the number's base-2 logarithm.

Comparison

equal? : Number Number -> Boolean
Produces true if the number is equal to the other number.

not-equal? : Number Number -> Boolean
Produces true if the numbers are not equal.

less-than? : Number Number -> Boolean
Produces true if the second number is less than the first.

greater-than? : Number Number -> Boolean
Produces true if the second number is greater than the first.

less-than-equal? : Number Number -> Boolean
Produces true if the second number is less than or equal to the first.

greater-than-equal? : Number Number -> Boolean
Produces true if the second number is greater than or equal to the first.

Trigonometric Functions

sine : Number -> Number
Produces the sine of the number. Number is expected to be in radians

cosine : Number -> Number
Produces the cosine of the number. Number is expected to be in radians.

tangent : Number -> Number
Produces the tangent of the number. Number is expected to be in radians.

arcsine : Number -> Number
Produces the arcsine of the number. Number is expected to be between 1 and -1. Output is between -π/2 and π/2.

arccosine : Number -> Number
Produces the arccosine of the number. Number is expected to be between 1 and -1. Output is between 0 and π.

arctangent : Number -> Number
Produces the arctangent of the number. Output is between -π/2 and π/2. Numbre

arctangent2 : Number Number -> Number
Produces the arctangent of the second number divided by the first number. Output is between π (inclusive) and -π (exclusive). Handles any asymptotes in that range.

hyperbolic-sine : Number -> Number
Produces the hyperbolic sine of the number. Domain and range are all real numbers.

hyperbolic-cosine : Number -> Number
Produces the hyperbolic cosine of the number. Domain is all real numbers, and range is from 1 to infinity.

hyperbolic-tangent : Number -> Number
Produces the hyperbolic tangent of the number. Domain is all real numbers, and range is from negative one to positive one, not inclusive.

hyperbolic-arcsine : Number -> Number
Produces the hyperbolic arcsine of the number. Output has the same sign as the input.

hyperbolic-arccosine : Number -> Number
Produces the hyperbolic arccosine of the number. Output is always positive.

hyperbolic-arctangent : Number -> Number
Produces the hyperbolic arctangent of the number. Output has the same sign as the input.

Statistical Functions

Other Utilities

random : -> Number
Produces a random number between zero (inclusive) and one (exclusive). Not guarenteed to be cryptographically secure.

degrees-to-radians : Number -> Number
Input is interpreted as degrees, and is converted into radians. Output has the same sign as the input.

radians-to-degrees : Number -> Number
Input is interpreted as radians, and is converted into degrees. Output has the same sign as the input.