Arithmetic

x+y
x-y
x*y
x/y
x div y
x mod y
-x

Addition (+), subtraction (-), multiplication (*), and division (/) are all defined as usual. Division also offers two special operators: x div y is the integer quotient of x and y, and x mod y is the integer remainder.

Normal arithmetic precedence rules are followed: a+b*c means a+(b*c). Parentheses may be used to clarify.

?a..b?, ?a,b,c?: Random numbers and choices

?start..end?
?val1,val2,val3,?

Randomly picks a value. In the first form, the value is any floating-point number in the given range (inclusive). In the second form, you list out all the values and one of them is randomly picked. The first form always operates on numbers; the second form may use strings as well.

|x|, |x,y|: Magnitude (absolute value)

|number|
|x,y|

The first form computes the absolute value of number. This just makes negative numbers positive; another way of looking at it is that it just computes the distance from 0 to number.

The second form computes the distance from (0,0) to (x,y) in a 2-dimensional plane.

<x,y>: Angle to a point

<x,y>

Computes the angle, in degrees, from the positive X axis to the line from (0,0) to (x,y), counterclockwise. (x and y may be any numbers; they need not be on-screen pixel coordinates.)

For example, <1,1> is 45, <0,1> is 90, <-1,0> is 180, and <0,-1> is 270.

As a special case, the value of <0,0> is defined to be 0. (Since a line of any angle passes through just the point (0,0), we could have chosen any value we wanted, or made it an error, but 0 makes things easier.)

Rounding to integers

round x

Rounds x to the nearest integer, so that 1.2 becomes 1 and 1.8 becomes 2. 1.5 rounds up to 2 as well.

int x

Chops off the fractional part of x, so that 1.2, 1.8, and 1.5 all become 1, and -1.2, -1.8, and -1.5 all become -1.

ceiling x

Rounds x up to the next larger integer, so that 1.2, 1.8, and 1.5 all become 2, and -1.2, -1.8, and -1.5 all become -1.

floor x

Rounds x down to the next lower integer, so that 1.2, 1.8, and 1.5 all become 1, and -1.2, -1.8, and -1.5 all become -2.

sqrt: Square root

sqrt value

Returns the square root of value. If value is negative, ends the program with an error.

curt: Cube root

curt x

Computes the cube root of x.

sgn: Get the sign of a number

sgn x

Returns -1 if x is less than zero, 0 if x is equal to zero, or 1 if x is greater than zero.

exp: Exponential growth

exp x

Returns e raised to the power of x, where e is Euler's constant, roughly equal to 2.71828. This is the opposite of ln.

ln: Natural logarithm

ln x

Returns the natural logarithm of x. Causes an error if x is less than or equal to zero. This is the opposite of exp.

Trig functions

sin angle
cos angle
tan angle
cotan angle
sec angle
cosec angle

Returns the sine, cosine, tangent, cotangent, secant, or cosecant of angle, which must be given in degrees.

Note these identities:

tan a = sin a / cos a
cotan a = cos a / sin a
sec a = 1 / cos a
cosec a = 1 / sin a

Since both cosine and sine functions can be 0, the tangent, cotangent, secant, and cosecant functions can each create a division-by-zero error at the appropriate place.