Note: The following functions should not be considered a complete list of all available thinBasic numeric functions, but this set will probably do for 99% of your requirements. If time permits, explore the full thinBasic Help document to review the complete set. Enter HELP thinBasic at the SPFLite command prompt to open the thinBasic help file.

ABS |
Num-var = ABS(numeric-expression) |

Return the absolute value of a expression.

The absolute value of a number is its non-negative value . For example, the absolute value of -3 is 3, and the absolute value of +3 is also 3. The absolute value of 0 is 0.

ATN |
Num-var = ATN(numeric-expression) |

Return the arctangent of an argument.

ATN returns the arctangent (Inverse Tangent) of numeric-expression; that is, the angle whose tangent is numeric-expression.

The result is in radians rather than degrees. To convert radians to degrees, multiply the radian value by 180/pi, or 57.29577951308232.

CEIL |
Num-var = CEIL(numeric-expression) |

Convert a variable or expression into an value, by returning the smallest integral value that is greater than or equal to its argument.

The CEIL function rounds upward, returning the smallest integral value that is greater than or equal to numeric-expression.

For example, y = CEIL(1.5) places the value 2 into y.

CHOOSE |
Num-var = CHOOSE(index, string-expression [,string-expression] ... ) |

Return one of several values, based upon the value of an index. It returns one of the parameters based upon the value of index. That is, if index is one, choice1 is returned. If two, choice2 is returned, etc. If index is not equal to one of the choice values, 0 is returned.

COS |
Num-var = COS(numeric-expression) |

Return the cosine of an argument.

numeric-expression is an angle specified in radians. To convert radians to degrees, multiply by 57.29577951308232##. To convert degrees to radians, multiply by 0.0174532925199433.

COS returns a value that always ranges between -1 and +1 inclusive.

DECR |
DECR numeric-variable |

Decrement a variable by 1.

Note: A variable may also be decremented by the notation variable -= 1

EXP EXP2 EXP10 |
Num-var = EXP(numeric-expression) |

Return a base number raised to a power. The base is e for EXP, 2 for EXP2, and 10 for EXP10.

EXP returns e to the nth power, where n is a numeric variable or expression and e is the base for natural logarithms, approximately 2.718282. Among other uses, this provides a simple way to obtain the value of e itself:

e = EXP(1)

EXP2(n) returns 2 to the nth power, where n is a numeric variable or expression.

EXP10(n) returns 10 to the nth power, where n is a numeric variable or expression.

The EXP functions provide a convenient alternative to the ^ operator, which works with any base.

FIX |
Num-var = FIX(numeric-expression) |

Truncate a number to an integer value.

FIX strips off the fractional part of its argument, and returns the integer part. Unlike INT, FIX does not perform any form of rounding or scaling.

FALSE TRUE |
Same as literal value of 0 Same as literal value of -1 |

FALSE and TRUE may be used anywhere the literal values of 0 and -1 can be used, including the VALUE clause of DIM statements.

Be aware that, while the value of TRUE is -1, a "true" value for purposes of conditional expressions such as in IF statements is a non-zero value, not just the value -1. This is similar to how conditions are tested in the C language. You can use TRUE and FALSE to set a flag variable, and you can test a flag for FALSE, but it's best not to test a flag for TRUE. Instead of using IF flag = TRUE THEN, you should simply say IF flag THEN. If you want to force a numeric expression to be exactly equal to either TRUE or FALSE, you can use the thinBasic function IsTrue.

FRAC |
Num-var = FRAC(Numeric-expression) |

Return the fractional part of a number.

FRAC returns the number after the decimal point of a number or expression. FRAC rounds the result to fit the precision of Numeric Expression..

IIF |
Num-var = IIF(Num-expression, true-part, false-part) |

Return one of two values based upon a TRUE/FALSE evaluation.

If num-expression evaluates to TRUE (non-zero), the true-part is returned, else the false-part is returned. num-expression is evaluated as a normal Boolean expression.

Both true-part and false-part should generate a normal numeric return value.

Compare to the IIF$ function.

INCR |
INCR numeric-variable |

Increment a variable by 1.

Note: A variable may also be incremented by the notation variable += 1

INT |
Num-var = INT(Num-expression) |

INT rounds num-expression to the largest integral value that is less than or equal to num_expression.

ISFALSE ISTRUE |
ISFALSE(expression) ISTRUE(expression) |

ISTRUE returns -1 (TRUE) when expression evaluates as non-zero; otherwise, it returns zero (FALSE). ISFALSE returns -1 when expression evaluates as 0 (FALSE); otherwise, it returns zero.

Truth table |
||

operator |
expression |
Result |

ISTRUE |
= 0 |
0 (False) |

ISTRUE |
<> 0 |
-1 (True) |

ISFALSE |
= 0 |
-1 (True) |

ISFALSE |
<> 0 |
0 (False) |

MAX |
Num-var = MAX(Number1, [,Number2] ...) |

Return the argument with the largest (maximum) value.

This function takes any number of arguments and return the argument with the largest (maximum) value.

MIN |
Num-var = MIN(Number1, [,Number2] ...) |

Return the argument with the smallest (minimum) value.

This function takes any number of arguments and return the argument with the smallest (minimum) value.

MOD |
Num-var = MOD(Quotient, Divisor) |

Return the remainder of the division between two numbers.

The MOD operator divides the two operands, Quotient and Divisor, and returns the remainder of that division. The result of the initial division is truncated to an integer value, before the remainder is calculated.

RANDOMIZE |
[ number ] |

Seed the random number generator.

number is a seed value. If number is not specified, a random value based on the TIME is used.

Values returned by the random number generator (RND) depend on an initial seed value. For a given seed value, RND always returns the same sequence of values, yielding a predictable pseudo-random number sequence. Thus, any program that depends on RND will run exactly the same way each time unless a different seed is given.

RND |
Num-var = RND(From-value, To-Value) |

Return a random number.

If no operands are provided, RND returns a random value that is less than 1, but greater than or equal to 0. Numbers generated by RND aren't really random, but are the result of applying a pseudo-random transformation algorithm to a starting ("seed") value. Given the same seed, the RND algorithm always produces the same sequence of "random" numbers.

When From-value and To-value are provided, RND(a, b) returns a integer in the range of a to b inclusive. a and b can each be a numeric literal or a numeric expression.

ROUND |
Num-var = ROUND(Num-exprerssion, Num-decimal-places) |

Round a numeric value to a specified number of decimal places.

Num-decimal-places is an expression specifying the number of decimal places required in the result.

Rounding is done according to the "banker's rounding" principle: if the fractional digit being rounded off is exactly five, with no trailing digits, the number is rounded to the nearest even number. This provides better results, on average, than the simple "round up at five" approach.

A% = ROUND(0.5, 0) ' 0

A% = ROUND(1.5, 0) ' 2

A% = ROUND(2.5, 0) ' 2

A% = ROUND(2.51, 0) ' 3

SGN |
Num-var = SGN(Num-exprerssion) |

Return the sign of a numeric expression.

If num-expression is positive, SGN returns 1. If num-expression is zero, SGN returns 0. If num-expression is negative, SGN returns -1.

SIN |
Num-var = SIN(Num-exprerssion) |

Return the sine of its argument.

num-expression is an angle specified in radians. SIN returns a value between -1 and +1.

To convert radians to degrees, multiply by 57.29577951308232. To convert degrees to radians, multiply by 0.0174532925199433.

SQR |
Num-var = SQR(Num-exprerssion) |

Return the square root of its argument.

num-expression must be greater than or equal to zero. SQR calculates square roots using an optimized algorithm. That is, y = SQR(x) takes less time to execute than y = x^0.5.

Attempting to take the square root of a negative number does not produce any run-time errors, but the results of such an operation are undefined.

Note that unlike some other languages, the square root function is SQR and not SQRT.

Created with the Personal Edition of HelpNDoc: Easily create PDF Help documents