Jasmine's operators and function set
Before looking further the user must be made aware that Jasmine is case sensitive. So sqrt, SQRT and Sqrt are all treated differently.
Data Types
Internally Jasmine uses the double data type throughout and will attempt to convert any other data type to this. Boolean values are stored as 1.0 (true) and 0.0 (false).
Variables
All variable names must start with the an upper or lowercase letter (A-Z or a-z) followed by any combination of upper (A-Z) or lower (a-z) case letters, digits (0-9) or underscores (_).
Expression Operators
The following table shows all the operators supported in the
expression operator set.Apart from the precedence operators thay are
all infix operators and expect 2 operands e.g. a OP b
.
Note: all of these operators also appear in the algorithm set.
Mathematical operators | |
---|---|
Operator | Description |
+ | Addition or string concatenation if either operand is type String |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
^ | Raises one number to the power of another e.g. 28 is calculated with 2 ^ 8 |
Logical operators | |
Operator | Description |
&& | Logical And between 2 boolean expressions |
|| | Logical Or between 2 boolean expressions |
^^ | Logical Exclusive-Or between 2 boolean expressions |
Comparison operators These are used to compare two numeric values. |
|
== | Is equal to |
!= | Is not equal to |
> | Is greater than |
>= | Is greater than or equal to |
< | Is less than |
<= | Is less than or equal to |
Precedence operators | |
( ) | Parentheses - used to change the order of evaluation and to surround the function parameters |
, | The comma separates the parameters passed in function calls |
Expression Functions
The following table shows the functions supported in the expression operator set. Every function has a unique name and a fixed number of parameters, Jasmine does not support function overloading.
Note: all of these functions also appear in the algorithm set.
Math functions | |
---|---|
Operator | Description |
abs(a) | Returns the absolute (positive) value of a |
cbrt(a) | Returns the cube root of a |
ceil(a) | Returns the smallest (closest to negative infinity) whole number that is >= a |
constrain(v,r0,r1) | Constrains value to inclusive range r0 --> r1 |
dec(a) | Returns the value a-1 |
exp(a) | Returns the exponential of a (ea) |
floor(a) | Returns the largest (closest to positive infinity) whole number that is <= a |
inc(a) | Returns the value a+1 |
lerp(r0, r1, t) | Linear interpolation between r0 and r1. t is normally ≥ 0.0 and ≤ 1.0 |
log10(a) | Returns the base 10 logarithm of a |
log(a) | Return the natural logarithm (base e) of a |
map(a,a0,a1,b0,b1) | Map value from range a into range b |
max(a, b) | Returns the larger of a and b |
min(a, b) | Returns the smaller of a and b |
neg(a) | Returns the negated value of a (i.e. -a) |
not(b) | Returns the logical 'not' on a boolean expression (i.e. !b) |
pow(a, b) | Raises one number to the power of another, 28 is calculated with pow(2 , 8) |
random(a,b) | Generates a random number >=a and <b |
round(a) | Returns the closest integer to a |
signum(a) | Returns -1.0 if a < 0.0, +1.0 if a > 0.0 and 0.0 if a == 0.0 |
sqrt(a) | Returns the square root of a |
Trignometric functions These functions expect angles to be in radians |
|
Operator | Description |
cos(a) | Returns the cosine of a |
cosh(a) | Returns the hyperbolic cosine of a |
acos(a) | Returns the arc cosine of a |
sin(a) | Returns the sine of a |
sinh(a) | Returns the hyperbolic sine of a |
asin(a) | Returns the arc sine of a |
tan(a) | Returns the tangent of a |
tanh(a) | Returns the hyperbolic tangent of a |
atan(a) | Returns the arc tangent of a |
atan2(y,x) | Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). |
radians(nd) | Converts degrees to radians |
degrees(nr) | Converts radians to degrees |
Constants
A small number of constants are defined in Jasmine
Symbol | Description |
---|---|
E | e - the base of the natural logarithms. 2.7182818284590452354 |
PI | pi - the ratio of the circumference of a circle to its
diameter 3.14159265358979323846 |
TAU | pi - the ratio of the circumference of a circle to its
radius 6.283185307179586 |
TRUE | double representation of the boolean true (1.0) |
FALSE | double representation of the boolean false (0.0) |
Algorithm operators and programming constructs
All the operators and functions above can be used in algorithms but to evaluate algorithms Jasmine also includes support for a number of conditional and loop constructs.
If-then-else conditional construct | |
---|---|
if(b) - then - else - endif |
Select the expressions to be evaluated based on
the boolean value b. The keyword 'then' is optional and can be replaced by a separator (;) |
While-wend loop construct | |
while(b) - wend | While the boolean b is true continue evaluating the expreesions inside the loop |
Repeat-until loop construct | |
repeat - until(b) | Keep evaluation the evaluating the expreesions inside the loop until the boolean b is true |
For loop construct | |
for(init, b, pb) fend |
Initialise the loop with the init statement and continue looping while b is true. The statement pb is the evaluated after the statements in the body of the loop. |
Other operators | |
= | Assignment operator stores the value on the right in the variable on the left. |
stop() | Stop evaluation of the algorithm |
Precedence operators | |
( ) | Parentheses - used to change the order of evaluation and to surround the function parameters |
, | The comma separates the parameters passed in function calls |
; | The semicolon separates the expressions / statements when on the same line |