-
Notifications
You must be signed in to change notification settings - Fork 2
Operators and Functions
alxnull edited this page Sep 25, 2019
·
1 revision
As of version 0.2.0, Calcex.Core supports the following pre-defined operators, functions, constants and symbols:
Symbol | Description | Example | Result |
---|---|---|---|
+ | Adds two numbers | 12 + 5 | 17 |
- | Subtracts two numbers | 9 - 4 | 5 |
* | Multiplies two numbers | 4 * 6 | 24 |
/ | Divides two numbers | 35 / 2 | 17.5 |
^ | Raises a number to the specified power | 4 ^ 3 | 64 |
% | Calculates the remainder of the division of two numbers | 23 % 4 | 3 |
= | Checks if two values are equal | 2*4 = 8 | true |
< | Checks if one value is less than another | 8 < 10 | true |
> | Checks if one value is greater than another | 4.5 > -3 | true |
<= | Checks if one value is less or equal compared to another | 5 <= 5 | true |
>= | Checks if one value is greater or equal compared to another | 8 >= 7 | true |
<> | Checks if two values are not equal | 12 <> 14 | true |
&& | Performs a boolean and operation between two values | 2 < 3 && 3 < 2 | false |
|| | Performs a boolean or operation between two values | 2 < 3 || 3 < 2 | true |
& | Performs a bitwise and operation between two values | 6 & 11 | 2 |
| | Performs a bitwise or operation between two values | 6 | 11 | 15 |
^| | Performs a bitwise xor operation between two values | 6 ^| 11 | 13 |
<< | Performs an arithmetic left shift | 8 << 2 | 32 |
>> | Performs an arithmetic right shift | -24 >> 2 | 6 |
>>> | Performs a logical (unsigned) right shift of an integer value | ||
sqrt | Calculates the square root of a number | sqrt(49) | 7 |
cbrt | Calculates the cubic root of a number | cbrt(27) | 3 |
exp | Raises e to the specified power. | exp(2) | e^2 |
sin | Calculates the sine of an angle | sin(0) | 0 |
cos | Calculates the cosine of an angle | cos(pi) | -1 |
tan | Calculates the tangent of an angle | tan(0) | 0 |
asin | Calculates the angle whose sine is the given number | asin(0) | 0 |
acos | Calculates the angle whose cosine is the given number | acos(-1) | pi |
atan | Calculates the angle whose tangent is the given number | atan(0) | 0 |
cosh | Calculates the hyperbolic cosine of a number | cosh(0) | 1 |
sinh | Calculates the hyperbolic sine of a number | sinh(0) | 0 |
tanh | Calculates the hyperbolic tangent of a number | tanh(0) | 0 |
rad | Converts an angle from degrees to radians | rad(180) | pi |
deg | Converts an angle from radians to degrees | deg(pi) | 180 |
lg | Calculates the base 10 logarithm of a number | lg(10) | 1 |
ln | Calculates the natural logarithm of a number | ln(e) | 1 |
log | Calculates the logarithm of a number | log(2, 8) | 3 |
neg | Negates a number | neg -23 | 23 |
abs | Returns the absolute value of a number | abs(-15) | 15 |
ceil | Returns the smallest integer greater than or equal to the given number | ceil(2.7) | 3 |
flr | Returns the largest integer less than or equal to the given number | flr(2.7) | 2 |
rnd | Rounds the given number to the nearest integer | rnd(2.7) | 3 |
sgn | Returns the sign of a number | sgn(-5) | -1 |
trun | Returns the integral part of a number | trun(3.54) | 3 |
min | Returns the minimum of a given range of values | min(6, -5, 2) | -5 |
max | Returns the maximum of a given range of values | max(6, -5, 2) | 6 |
avg | Calculates the arithmetic mean of a given range of values | avg(6, -5, 2) | 1 |
and | Performs a boolean 'and' operation between all given values | and(true, false, 0=0) | false |
or | Performs a boolean 'or' operation between all given values | or(true, false, 0=0) | true |
not | Performs a boolean 'not' operation | not true | false |
xor | Performs a boolean 'xor' operation between all given values | xor(true, false, 0=0) | false |
fact | Calculates the factorial of a number | fact(5) | 120 |
if | Returns one of two values based on a condition | if(-5 >= 0, 1, -1) | -1 |
sum | Calculates the sum of a sequence of terms | sum(i, 1, 10, 2^i) | 2046 |
prod | Calculates the product of a sequence of terms | prod(i, 1, 5, i) | 120 |
pi | Represents the number Pi | ||
e | Represents Euler's number | ||
true | Represents the boolean true (has value 1) | ||
false | Represents the boolean false (has value 0) | ||
( | An opening bracket | ||
) | A closing bracket |