4.8. The Math Library

Kick Assembler's math library is built upon the Java math library. This means that nearly every constant and command in Java's math library is available in Kick Assembler. Here is a list of available constants and commands. For further explanation consult the Java documentation at Suns homepage. The only non Java math library function is mod (modulo).

Table 4.5. Math Constants

Constant Value
PI 3.141592653589793
E 2.718281828459045

Table 4.6. Math Functions

Function Description
abs(x) Returns the absolute (positive) value of x.
acos(x) Returns the arc cosine of x.
asin(x) Returns the arc sine of x.
atan(x) Returns the arc tangent x
atan2(y,x) Returns the angle of the coordinate (x,y) relative to the positive x-axis. Useful when converting to polar coordinates.
cbrt(x) Returns the cube root of x.
ceil(x) Rounds up to the nearest integer.
cos(r) Returns the cosine of r.
cosh(x) Returns the hyperbolic cosine of r.
exp(x) Returns ex.
expm1(x) Returns ex-1.
floor(x) Rounds down to the nearest integer.
hypot(a,b) Returns sqrt(x2+y2).
IEEEremainder(x,y) Returns the remainder of the two numbers as described in the IEEE 754 standard.
log(x) Returns the natural logarithm of x.
log10(x) Returns the base 10 logarithm of x.
log1p(x) Returns log(x+1).
max(x,y) Returns the highest number of x and y.
min(x,y) Returns the smallest number of x and y.
mod(a,b) Converts a and b to integers and returns the remainder of a/b.
pow(x,y) Returns x raised to the power of y.
random() Returns a random number x where 0 ≤ x < 1.
round(x) Rounds x to the nearest integer.
signum(x) Returns 1 if x>0, -1 if x<0 and 0 if x=0.
sin(r) Returns the sine of r.
sinh(x) Returns the hyperbolic sine of x.
sqrt(x) Returns the square root of x.
tan(r) Returns the tangent of r.
tanh(x) Returns the hyperbolic tangent of x.
toDegrees(r) Converts a radian angle to degrees.
toRadians(d) Converts a degree angle to radians.

Here are some examples of use.

        // Load a with a random number
        lda #random()*256

        // Generate a sine curve
        .fill 256,round(127.5+127.5*sin(toRadians(i*360/256)))