| Previous | Contents | Index |
SheerPower has numerous built-in functions. This chapter describes the system and other built-in functions.
The following are common math functions that SheerPower performs:
CEIL(x) returns the ceiling of x. The ceiling of x is equal to the smallest integer that is not less than x.
| Example 6-1 CEIL function |
|---|
print ceil(1.543) 2 |
The DIV0 function divides num_expr1 by num_expr2. If num_expr2 (divisor) is 0, 0 is returned.
| Example 6-2 DIV0 function |
|---|
print div0(0.8, 0.000004) print div0(0.8, 0.0) print div0(6, 3) print div0(6, 0) end 200000 0 2 0 |
Given a number, the FP function returns the fractional part of the number. See Section 6.1.6, IP(num_expr).
| Example 6-3 FP function |
|---|
print fp(238.304) .304 |
INT returns the whole portion of a real number as a real number.
| Example 6-4 INT function |
|---|
print int(148.8432) 148 |
INTEGER changes any numeric expression into an integer value and assigns the integer value to the variable specified.
| Example 6-5 INTEGER function |
|---|
z = integer(4 + (993 * 35)) print z end 34759 |
IP truncates the value of a real number at the decimal point and returns the integer portion. See Section 6.1.3, FP(num_expr).
| Example 6-6 IP function |
|---|
print ip(1234.56) 1234 |
MAX(x,y) returns the larger of the two values x and y. See also "MIN function".
| Example 6-7 MAX function |
|---|
print max(5, 9) 9 |
MIN(x,y) returns the lesser of the values x and y. See also "MAX function".
| Example 6-8 MIN function |
|---|
x = 43 y = 19 print min(x, y) 19 |
MOD gives the remainder of one number divided by another.
| Example 6-9 MOD function |
|---|
print mod(36, 13) 10 |
REAL changes any numeric expression into a real or floating-point value and assigns the real value to the variable specified.
| Example 6-10 REAL function |
|---|
input 'Your age': age% let decimal_age = real(age%) print 'Your number is'; decimal_age end Your age? 31 Your number is 31 |
REMAINDER(x,y) returns the remainder when X is divided by Y. It differs subtly from MOD. MOD(-4,3) = 2 while REMAINDER(-4,3) = -1.
| Example 6-11 REMAINDER function |
|---|
print remainder(-4,3) -1 |
or
RND returns a random number greater than or equal to zero and less than one. If a numeric expression (num_expr) is given, RND returns a whole number between one and the numeric expression.
| Example 6-12 RND function |
|---|
print rnd .9409720199182629 |
ROUND rounds a num_expr to the specified number of decimal places (int_expr). The default int_expr is 0.
| Example 6-13 ROUND function |
|---|
print round(21.83492, 2) 21.83 |
This function truncates a real number to a given number of decimal places.
| Example 6-14 TRUNCATE function |
|---|
print truncate(123.45678, 2) print truncate(123.45678, 4) end 123.45 123.4567 |
The following are transcendental functions that SheerPower performs:
ABS returns the absolute value of a specified numeric expression.
| Example 6-15 ABS function |
|---|
print abs(-5) 5 |
The arccosine of X (ACOS(x)) returns the angle whose COS is x. The angle is returned in radians. ACOS has to be between -1 and +1 (inclusive).
| Example 6-16 ACOS function |
|---|
print acos(.75) .722734247813 |
Given X and Y coordinates, the ANGLE function returns the angle from 0,0 in radians.
| Example 6-17 ANGLE function |
|---|
print angle(4,9) 1.152571997216 |
The arcsine of X (ASIN(x)) returns the angle whose SIN is x. The angle is returned in radians. ASIN has to be between -1 and +1 (inclusive).
| Example 6-18 ASIN function |
|---|
print asin(.3) .304692654015 |
Arctangent (ATN) returns the angle, in radians, of a specified tangent.
| Example 6-19 ATN function |
|---|
print atn(33) 1.540502566876 |
COS returns the cosine of an angle the user specifies in radians.
| Example 6-20 COS function |
|---|
print cos(64)
.39185723043
|
COSH returns the hyperbolic cosine of a passed real number.
| Example 6-21 COSH function |
|---|
print cosh(31)
14524424832623.712890625
|
Cotangent (COT(X)) is equivalent to 1/TAN(X).
| Example 6-22 COT function |
|---|
print cot(31)
-2.2640027937804799
|
| Example 6-23 CSC function |
|---|
print csc(187)
-1.0028370028157145
|
| Previous | Next | Contents | Index |