,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 9
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
6-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)

,ce
PREDECLARED FUNCTIONS

OmegaSoft Pascal features a wide range of predeclared functions, both ISO standard and extensions. The predeclared functions will be presented by category, and within a category, alphabetically.

,ce
ARITHMETIC FUNCTIONS

ABS

Returns the absolute value of its parameter. The result type will be the same type as the parameter and will be positive regardless of the sign of the parameter.

abs (5) = 5    abs (-5) = 5

abs-function = abs ( (integer-expression | real-expression |
                          longinteger-expression) )

ARCCOS

Returns the arc cosine (in radians) of its parameter. The result type will be real. The parameter may be in the range of -1 to 1 inclusive, any parameter outside of this range will generate an overflow error at runtime.

arccos-function = arccos ( (integer-expression | real-expression 
                           | longinteger-expression) )

ARCSIN

Returns the arc sine (in radians) of its parameter. The result type will be real. The parameter may be in the range of -1 to 1 inclusive, any parameter outside of this range will generate an overflow error at runtime.

arcsin-function = arcsin ( (integer-expression | real-expression 
                             | longinteger-expression) )

ARCTAN

Returns the arc tangent (in radians) of its parameter. The result type will be real.

arctan-function = arctan ( (integer-expression | real-expression 
                | longinteger-expression) )

COS

Returns the cosine of its parameter. The result will be in radians. The result type will be real. The parameter may be in the range of -51000 to 51000 inclusive, any parameter outside of this range will generate a truncation error at runtime.

cos-function = cos ( (integer-expression | real-expression 
                            | longinteger-expression) )
,pg
,ce
ARITHMETIC FUNCTIONS

EXP

Returns the value of E raised to the power of the parameter. The result type will be real. The exp function is equivalent to e ** parameter with e being equal to 2.718282 . The parameter must in the range of -87 to 87 for real, any parameter outside of this range will generate an overflow error at runtime.

exp-function = exp ( (integer-expression | real-expression
                            | longinteger-expression) )

LN

Returns the natural logarithm (base e) of the parameter. The result type will be real. The parameter must not be zero or negative or else it will generate an invalid argument for square root or log error at runtime.

ln-function = ln ( (integer-expression | real-expression
                          | longinteger-expression) )

LOG

Returns the common logarithm (base 10) of the parameter. The result type will be real. The parameter must not be zero or negative or else it will generate an invalid argument for square root or log error at runtime.

log-function = log ( (integer-expression | real-expression
                            | longinteger-expression) )

RANDOM

Returns a pseudo-random real value between (but not including) 0.0 and 1.0 . The parameter must be a real variable identifier and will be used a 32 bit shift register with feedback. The parameter is first shifted, the upper 9 bits are masked off to make the number between 0.5 and 1.0, 0.5 is then subtracted to get the number between 0.0 and 0.5, the number is then multiplied by 2 to get the final result between 0.0 and 1.0 . 

The parameter should be initialized to a non-zero number before use, as zero is the only forbidden state for the "seed". The initialization number should have a good distribution of 1's and 0's to provide a even distribution, 0.5 is a very bad choice (only 1 bit on) while non powers of two like pi or e are good choices.

Example :  seed := pi ;
           for i := 1 to 10 do
             writeln (random (seed)) ;

random-function = random ( real-variable )
,pg
,ce
ARITHMETIC FUNCTIONS

SIN

Returns the sine of its parameter. The result will be in radians. The result type will be real. The parameter may be in the range of -51000 to 51000 inclusive, any parameter outside of this range will generate a truncation error at runtime.

sin-function = sin ( (integer-expression | real-expression 
               | longinteger-expression | longreal-expression) )

SQR

Returns the square of its parameter. The result type will be the same type as the parameter. This function is equivalent to parameter * parameter and will generate less code and execute in approximately the same amount of time (logs are not used).

sqr-function = sqr ( (integer-expression | real-expression 
                       | longinteger-expression) )

SQRT

Returns the square root of the parameter. The result type will be real. The parameter must not be zero or negative or else it will generate an invalid argument for square root or log error at runtime.

sqrt-function = sqrt ( (integer-expression | real-expression
                           | longinteger-expression) )

TAN

Returns the tangent of its parameter. The result will be in radians. The result type will be real. The parameter may be in the range of -51000 to 51000 inclusive, any parameter outside of this range will generate a truncation error at runtime.

tan-function = tan ( (integer-expression | real-expression 
                           | longinteger-expression) )

,ce
TYPE CONVERSION FUNCTIONS

The OmegaSoft Pascal compiler features an orthogonal method of converting between the nine basic data types : boolean, enumerated type, character, integer, longinteger, hex, longhex, real, and string. The method is to use the desired type as the function name, or the standard identifier "enum" for enumerated type.

In general there is only one parameter. When converting from real to anything other than real or string a second parameter may be used. The second parameter may be "round", "trunc", or "floor" and if not used then rounding will be used. Other cases where a second parameter is allowed will be pointed out where applicable. 

If you convert from one type to the same type, no code is generated. Many other instances also will generate no code, only changes in the type of expression, these cases occur if the type of parameter is not mentioned in the description for the general type conversion functions (boolean, enum, char, integer, hex, longhex, longinteger, real, and string).
,pg
,ce
TYPE CONVERSION FUNCTIONS

conv-parm = (boolean-expression | enumerated-type-expression |
             character-expression | integer-expression |
             hex-expression | longhex-expression |
             longinteger-expression | string-expression)

real-round = real-expression {, (round | trunc | floor) }

BOOLEAN

Converts its parameter into a boolean value. For enumerated type, character, integer, and hex parameters the least significant byte is simply "anded" with one and is equivalent to the odd function. For longinteger and longhex parameters the 4 byte value is removed from the stack, with only the least significant byte being retained, which is then anded with one. For a real parameter it is first converted to an integer and then anded. When using a string parameter it must not have any leading spaces and the first letter must be a Y, T, N, or F (or lower case equivalents) or else a conversion error will be generated. If the first letter is a Y, or T then boolean true will be returned, if the first letter is a N or F then a boolean false will be returned.

Examples : boolean (5) = true    boolean (4) = false
           boolean ('A') = true  boolean ('B') = false
           boolean (4.7) = true  boolean (4.7, trunc) = false

boolean-function = boolean ( (conv-parm | real-round) )

CHAR

Converts its parameter into a character. For longhex and longinteger parameters the 4 byte value is removed from the stack, with only the least significant byte being retained. For a real parameter the value is converted into an integer and only the least significant byte is retained. 

For a string parameter there is a second parameter allowed. The second parameter must be a byte or integer constant and specifies which byte of the string is to be returned as a character. 

If no second parameter is used then the first data byte of the string will be returned. Using a second parameter of zero will return the dynamic length.

Examples : char (true) = #1         char (53) = '5'
           char ($409A) = #$9A      char (5.3) = #5
           char ('test') = 't'      char ('test',3) = 's'

char-function = char ( conv-parm {, (character-constant |
                                     integer-constant)} )

CHR

Returns a character (byte) equivalent of its parameter. This is done by removing the most significant 8 bits of its parameter.

chr-function = chr ( (integer-expression | hex-expression) )
,pg
,ce
TYPE CONVERSION FUNCTIONS

ENUM

Converts its parameter into an enumerated type value. For longhex and longinteger parameters the 4 byte value is removed from the stack, with only the least significant byte being retained. For a real parameter the value is converted into an integer and only the least significant byte is retained. A string parameter is converted into an integer (see integer function with string parameter) and the least significant byte retained.

Examples : type
             enum1 = (green, yellow, blue, red, white, purple) ;

           enum (0) = green           enum (3) = red
           enum (5.3) = purple        enum ('02') = blue

enum-function = enum ( (conv-parm | real-round) )

FLOOR

Will return the integer equivalent of its parameter. The integer result will be the largest integer less than the real value. If the parameter cannot be represented as an integer a truncation error will be generated at runtime.

floor (4.6) = 4     floor (-4.6) = -5

floor-function = floor ( real-expression )

HEX

Will return the hex equivalent of its parameter. If the parameter is boolean, enumerated, or character, then a zero most significant byte will be added to form a word. If the parameter is longhex or longinteger then the 4 byte value is pulled from the stack and the least significant 2 bytes retained. If the parameter is real then the value will be converted to an integer and this result treated as a hex number (hex(-10000.0) would return $D8F0). With a string parameter it must not have any leading or trailing spaces or else a conversion error will be generated. The digits 0-9 and the letters A-F (or a-f) are acceptable for hexidecimal input. If the value exceeds $FFFF then a conversion error occurs.

Examples : hex (false) = $0           hex ('A') = $41
           hex (500) = $1F4           hex (375.6) = $178
           hex ('1FFF') = $1FFF

hex-function = hex ( (conv-parm | real-round) )

INTEGER

Will return the integer equivalent of its parameter. If the parameter is boolean, enumerated, or character, then a most significant byte will be added that is the sign extension of the original byte. If the parameter is longhex or longinteger then the 4 byte value is pulled from the stack and the least significant 2 bytes retained. If the parameter is real then the value will be converted to an integer. With a string parameter it must not have any leading or trailing spaces or else a conversion error will be generated.

,ce
TYPE CONVERSION FUNCTIONS

The digits 0-9 and a leading plus or minus are acceptable for decimal input. If the value exceeds plus or minus maxint then a conversion error occurs.

Examples : integer ('A') = 65   integer (#200) = -56

integer-function = integer ( (conv-parm | real-round) )

LONGHEX

Will return the longhex equivalent of its parameter. If the parameter is boolean, enumerated, or character, then 3 zero bytes will be added as the most significant and pushed on the stack. If the parameter is integer or hex then 2 zero bytes will be added as the most significant and pushed on the stack. If the parameter is real then the value will be converted to a longinteger similar to round, trunc, or floor. This value will then be treated as a longhex value (longhex(-3437138.0) will be $FFCB8DAE). With a string parameter it must not have any leading or trailing spaces or else a conversion error will be generated. The digits 0-9 and the letters A-F (or a-f) are acceptable for hexidecimal input. If the value exceeds $FFFFFFFF then a conversion error occurs.

longhex-function = longhex ( (conv-parm | real-round) )

LONGINTEGER

Will return the longinteger equivalent of its parameter. If the parameter is boolean, enumerated, or character, then 3 bytes will be added as the most significant reflecting the sign extension of the original byte, and pushed on the stack. If the parameter is integer or hex then 2 bytes will be added as the most significant reflecting the sign extension of the original most significant byte and then pushed on the stack. If the parameter is real then the value will be converted to a longinteger similar to round, trunc, or floor. With a string parameter it must not have any leading or trailing spaces or else a conversion error will be generated. The digits 0-9 and a leading plus or minus are acceptable for decimal input. If the value exceeds plus or minus maxlint then a conversion error occurs.

longinteger-function = longinteger ( (conv-parm | real-round) )

ODD

Returns a boolean result that represents the least significant bit of its parameter. This tells you whether the parameter is odd (ls bit one) or even (ls bit zero).

Examples : odd (5) = true     odd (4) = false

odd-function = odd ( (character-expression | integer-expression |
                      hex-expression | longinteger-expression |
                      longhex-expression) )


