SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index


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 

6.2.6 COS(num_expr)

COS returns the cosine of an angle the user specifies in radians.

Example 6-20 COS function

  print cos(64) 
        
 
 .39185723043 

6.2.7 COSH(num_expr)

COSH returns the hyperbolic cosine of a passed real number.

Example 6-21 COSH function

  print cosh(31) 
        
 
14524424832623.712890625 

6.2.8 COT(num_expr)

Cotangent (COT(X)) is equivalent to 1/TAN(X).

Example 6-22 COT function

  print cot(31) 
        
 
-2.2640027937804799 

6.2.9 CSC(num_expr)

CSC(x) is the cosecant of X. It is shorthand for 1/SIN(x).

Example 6-23 CSC function

  print csc(187) 
        
 
-1.0028370028157145 


Previous Next Contents Index