Previous | Contents | Index |
Example 5-20 OPTION BASE Statement |
---|
option base 0 dim name$(4) for i = 0 to 4 input 'Enter a name': name$(i) print i; ' Hello, '; name$(i) next i end Enter a name? June 0 Hello, June Enter a name? Tony 1 Hello, Tony Enter a name? Sandy 2 Hello, Sandy Enter a name? Carl 3 Hello, Carl Enter a name? Liz 4 Hello, Liz |
OPTION BASE is used to set the default low bound for arrays to suit your needs. You have the option of starting the array with element O or element 1.
When no low bound is specified for a dimension, the default is 1. The OPTION BASE statement lets you specify a default low bound of 0 or 1. When any following DIM or REDIM statements are executed, Sheerpower defaults the low bound to 0 or 1 as specified.
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 |
Previous | Next | Contents | Index |