Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

EXAMPLE:

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 

PURPOSE:

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.

DESCRIPTION:

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.


Chapter 6
Built-in Functions

Sheerpower has numerous built-in functions. This chapter describes the system and other built-in functions.

6.1 Common Math Functions

The following are common math functions that Sheerpower performs:

6.1.1 CEIL(num_expr)

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 

6.1.2 DIV0(num_expr1, num_expr2)

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 

6.1.3 FP(num_expr)

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 

6.1.4 INT(num_expr)

INT returns the whole portion of a real number as a real number.

Example 6-4 INT Function

  print int(148.8432) 
  
  
148 

6.1.5 INTEGER(num_expr)

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 

6.1.6 IP(num_expr)

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 

6.1.7 MAX(num_expr, num_expr)

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 

6.1.8 MIN(num_expr1, num_expr2)

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 

6.1.9 MOD(num_expr1, num_expr2)

MOD gives the remainder of one number divided by another.

Example 6-9 MOD Function

  print mod(36, 13) 
  
  
10 

6.1.10 REAL(num_expr)

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 

6.1.11 REMAINDER(num_expr1, num_expr2)

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 

6.1.12 RND

or

RND(num_expr)

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 

6.1.13 ROUND(num_expr [, int_expr])

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 

6.1.14 TRUNCATE(num_expr, int_expr)

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 

6.2 Transcendental Functions

The following are transcendental functions that Sheerpower performs:

6.2.1 ABS(num_expr)

ABS returns the absolute value of a specified numeric expression.

Example 6-15 ABS Function

  print abs(-5) 
 
 
5 

6.2.2 ACOS(num_expr)

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 

6.2.3 ANGLE(num_expr, num_expr)

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 

6.2.4 ASIN(num_expr)

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 

6.2.5 ATN(num_expr)

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