Expression 2 Number - wiremod/wire GitHub Wiki
<< Go back to Expression 2: Features
This is a full list of functions provided by E2's number extension. It will also include syntax for comparison operations and bitwise ops.
Syntax | Example | Description |
---|---|---|
> | if ( A>8 ) {} | Greater than comparison. Returns 1 when the left value is greater than the right value. |
< | if ( A<4 ) {} | Less than comparison. Returns 1 when the left value is less than the right value. |
>= | if ( A>=6 ) {} | Returns 1 when the right value is either greater than or equal to the left value. |
<= | if ( A<=14 ) {} | Returns 1 when the right value is either less than or equal to the left value. |
Function | Returns | Description |
---|---|---|
inrange(Nβ,Nβ,Nβ) |
![]() |
Returns 1 when the value Nβ is in between the arguments Nβ and Nβ. |
These functions pick the highest or lowest value of a set of numbers, and returns that.
Function | Returns | Description |
---|---|---|
min(N,N[,N,N]) |
![]() |
Selects the closest number to negative infinity and returns it. Requires 2 arguments, maximum of 4 arguments. |
max(N,N[,N,N]) |
![]() |
Selects the closest number to positive infinity and returns it. Requires 2 arguments, maximum of 4 arguments. |
clamp(Nβ,Nβ,Nβ) |
![]() |
Clamps the value Nβ to a minimum and maximum amount Nβ and Nβ, and returns the clamped amount. |
Pray you don't have to use these.
Function | Returns | Description |
---|---|---|
isfinite(N) |
![]() |
Returns 1 (true) if the given value is a finite number. |
isinf(N) |
![]() |
Returns 1 if the number is positive infinity, or -1 when it is negative infinity. Finite numbers return 0. |
isnan(N) |
![]() |
Returns 1 when the given value is not a number (NaN). |
Surprisingly not banned in 55 countries in regard to gambling regulations.
Function | Returns | Description |
---|---|---|
random([N]) |
![]() |
Returns a random float between 0-1. Optionally, multiply the result by the argument N. |
random(Nβ,Nβ) |
![]() |
Returns a random floating value between the arguments Nβ and Nβ. |
randint(N) |
![]() |
Returns a random integer between 1 and the given value. (Seems to behave weirdly when given negative values...) |
randint(Nβ,Nβ) |
![]() |
Returns a random integer between the values Nβ and Nβ inclusively. |
haha numbers go wheeeeeeee
Syntax | Example | Description |
---|---|---|
+ | 3 + 8 | Adds two values together and returns the result. |
- | A - B | Subtracts the right value from the left value, and returns the result. |
* | C * D | Multiplies the right and left values together, and returns the result. This can also multiply vectors as a scalar magnitude! |
/ | E / F | Divides the left value over the right value and returns an exact decimal answer. |
% | E % F | Divides the left value over the right value, and returns the remainder of the division. |
^ | 4 ^ N | Raises the left value to the Nth power exponent, and returns the result. |
Number variables can be reassigned a new value based on one of the basic arithmetic operators by simply appending an equal sign after it.
The format A += B
, is equivalent to doing A = A + B
. This works for any arithmetic operation.
There is also a shorthand form of this to increment/decrement a variable by just 1.
Syntax | Example | Description |
---|---|---|
++ | A++ | Increments variable A by 1 directly. |
-- | B-- | Decrements variable B by 1 directly. |
+= | A += B - C | Sets the variable A equal to itself, plus B-C. |
-= | A -= B + C | Sets the variable A equal to itself, minus B+C. |
*= | A *= D | Sets A equal to A * D. |
/= | A /= E | Sets A equal to A / E. |
%= | A %= G | Sets A equal to A % G. |
^= | A ^= H | Sets A equal to A to the power of H. |
Function | Returns | Description |
---|---|---|
abs(N) |
![]() |
Returns the positive form (magnitude) of the value, aka, the absolute value of the number. |
sign(N) |
![]() |
Returns the sign of the given value. 1 for positive values, -1 for negative values, and 0 for anything else. |
sqrt(N) |
![]() |
Returns the square root of the given value. |
cbrt(N) |
![]() |
Returns the cubic root of the given value. |
root(Nβ,Nβ) |
![]() |
Returns the Nβth root of the value Nβ |
ln(N) |
![]() |
Performs a logarithm with base e on the given value. |
log(Nβ,Nβ) |
![]() |
Performs a logarithm with an Nβth base on the given value Nβ. |
log2(N) |
![]() |
Performs a logarithm based 2 on the given value. |
log10(N) |
![]() |
Performs a logarithm based 10 on the given value. |
frexp(N) |
![]() |
Returns the mantissa and exponent of the given floating-point number as a vector2 (X component holds a mantissa, and Y component holds an exponent) |
wrap(Nβ,Nβ) |
![]() |
Performs (Nβ+Nβ) % (Nβ*2) - Nβ. Performs a wrapping calculation around 0 with a range of Nβ. wrap(89,90) returns 89, wrap(92,90) returns -88. |
Rounds to the nearest integer.
Function | Returns | Description |
---|---|---|
round(Nβ[,Nβ]) |
![]() |
Rounds to the nearest integer, optionally up to Nβ number of decimal places, from .5 up and anything below down. |
floor(Nβ[,Nβ]) |
![]() |
Rounds a number down towards -infinity, optionally up to Nβ number of decimal places. -1.4 returns -2, 2.6 returns 2. |
ceil(Nβ[,Nβ]) |
![]() |
Rounds a number up towards +infinity, optionally up to Nβ number of decimal places. -1.4 returns -1, 2.6 returns 3. |
int(N) |
![]() |
Rounds a number towards 0 to the nearest integer. -1.4 returns -1, 2.6 returns 2. |
frac(N) |
![]() |
Returns the decimal (fractional) component of a number. -1.4 returns -0.4, 2.6 returns 0.6. |
Scattah. A gift! For you!
(Note that trig functions in E2 work with degree-based values unless using the radian functions suffixed with "r".)
Function | Returns | Description |
---|---|---|
toRad(N) |
![]() |
Converts the value's unit from degrees into radians. 90Β° == π/2 |
toDeg(N) |
![]() |
Converts the value's unit from radians into degrees. π radians == 180Β° |
sin(N) |
![]() |
Returns the sine of value N. sin(90) = 1 |
cos(N) |
![]() |
Returns the cosine of value N. cos(0) = 1 |
tan(N) |
![]() |
Returns the tangent of value N. tan(45) = 1 |
asin(N) |
![]() |
Returns the sine inverse angle (arc sine) of value N. |
acos(N) |
![]() |
Returns the cosine inverse angle (arc cosine) of value N. |
atan(N) |
![]() |
Returns the tangent inverse angle (arc tangent) of value N. |
atan(Nβ,Nβ) |
![]() |
Returns the tangent inverse (arc tangent) of the values Nβ/Nβ. This function accounts for positive/negative values as appropriate, and arguments at or close to 0. |
csc(N) |
![]() |
Returns the cosecant of the value N. (csc(A)=B/C : sin(A)=C/B) |
sec(N) |
![]() |
Returns the secant of the value N. (sec(A)=B/C : cos(A)=C/B) |
cot(N) |
![]() |
Returns the cotangent of the value N. (cot(A)=B/C : tan(A)=C/B) |
sinh(N) |
![]() |
Returns the hyperbolic sine of the value N. |
cosh(N) |
![]() |
Returns the hyperbolic cosine of the value N. |
tanh(N) |
![]() |
Returns the hyperbolic tangent of the value N. |
csch(N) |
![]() |
Returns the hyperbolic cosecant of the value N. |
sech(N) |
![]() |
Returns the hyperbolic secant of the value N. |
coth(N) |
![]() |
Returns the hyperbolic cotangent of the value N. |
Function | Returns | Description |
---|---|---|
sinr(N) |
![]() |
Returns the sine of value N using radians. sinr(pi()/2) = 1 |
cosr(N) |
![]() |
Returns the cosine of value N using radians. cosr(0) = 1 |
tanr(N) |
![]() |
Returns the tangent of value N using radians. tanr(pi()/4) = 1 |
asinr(N) |
![]() |
Returns the sine inverse angle (arc sine) of value N using radians. |
acosr(N) |
![]() |
Returns the cosine inverse angle (arc cosine) of value N using radians. |
atanr(N) |
![]() |
Returns the tangent inverse angle (arc tangent) of value N using radians. |
atanr(Nβ,Nβ) |
![]() |
Returns the tangent inverse angle (arc tangent) of the values Nβ/Nβ, in radian measurement. This function accounts for positive/negative values as appropriate, and arguments at or close to 0. |
cscr(N) |
![]() |
Returns the cosecant of the value N using radians. (csc(A)=B/C : sin(A)=C/B) |
secr(N) |
![]() |
Returns the secant of the value N using radians. (sec(A)=B/C : cos(A)=C/B) |
cotr(N) |
![]() |
Returns the cotangent of the value N using radians. (cot(A)=B/C : tan(A)=C/B) |
sinhr(N) |
![]() |
Returns the hyperbolic sine of the value N using radians. |
coshr(N) |
![]() |
Returns the hyperbolic cosine of the value N using radians. |
tanhr(N) |
![]() |
Returns the hyperbolic tangent of the value N using radians. |
cschr(N) |
![]() |
Returns the hyperbolic cosecant of the value N using radians. |
sechr(N) |
![]() |
Returns the hyperbolic secant of the value N using radians. |
cothr(N) |
![]() |
Returns the hyperbolic cotangent of the value N using radians. |
Function | Returns | Description |
---|---|---|
inf() |
![]() |
β (equivalent to math.Huge()) |
pi() |
![]() |
π (equivalent to 3.141592653589793ββββββββββ...) |
_PI |
![]() |
Same as pi() but as a constant enumeration. |
exp(N) |
![]() |
Returns Euler's constant e to the power of the Argument (same as e()^N but shorter and faster this way) |
_E |
![]() |
Same as e() but as a constant enumeration. |
_PHI |
![]() |
Ο (equivalent to the golden ratio 1+sqrt(5) divided by 2) |
Developed by: asiekierka, TomyLobo (made xor), and Divran (added operators)
Bitwise operators act on numbers as if they were decimal-represented binary numbers.The individual bits of a number have operations taken against them.
For example, with 8 binary bits in a word, 00000000
, they can be either 0
or 1
each.
By performing bitwise operations, you're working on a logical level with each respective bit in an 8 bit word, compared with another word.
Binary Operation | Word 1 | Word 2 | Result | Description |
---|---|---|---|---|
AND | 11111100 (252) | 00111111 (63) | 00111100 (60) | AND operation. Maintains a bit level of 1 when both bits at that register are 1. Otherwise, flips bits to 0. |
OR | 11111100 (252) | 00111111 (63) | 11111111 (255) | OR operation. If there is a 1 on either word at that bit register, the resulting bit will be 1. Both bits must be 0 for a 0 bit. |
XOR | 11111100 (252) | 00111111 (63) | 11000011 (195) | Exclusive OR operation. Checks if there's a difference between the bits. A word's bit register must be 1, and the other 0, for a 1 bit to result. However, a 0 bit occurs when both bits are 0 or when both bits are 1. |
BSR | 11111100 (252) | - | 01111110 (126) | Bit shift right. Physically moves the bit registers one digit to the right. |
BSL | 11111100 (252) | - | 111111000 (504) | Bit shift left. Physically moves the bit registers one digit to the left. Note that in E2, this is not limited to only 8 bits! In fact, E2 uses a 32 bit register. You will need to carry over the extra 256 to the ones place or discard it if you want to remain on 8 bits. It's up to your own implementation. |
NOT | 11111100 (252) | - | 00000011 (3) | Binary NOT. Simply flips 1 bits to 0, and 0 bits to 1. |
Tip: You can also use N:toString(2) and S:toNumber(2) to perform bitwise manipulation using the string functions.
Function | Returns | Description |
---|---|---|
bOr(N,N) |
![]() |
Performs bitwise OR against the two numbers (Operator: N || N) |
bAnd(N,N) |
![]() |
Performs bitwise AND against the two numbers (Operator: N && N) |
bXor(N,N) |
![]() |
Performs bitwise XOR against the two numbers (Operator: N ^^ N) |
bShl(N,N) |
![]() |
Performs bitwise shift left on the first number by the amount of the second (Operator: N << N) |
bShr(N,N) |
![]() |
Performs bitwise shift right on the first number by the amount of the second (Operator: N >> N) |
bNot(N) |
![]() |
Performs a binary Not |
bNot(N,N) |
![]() |
Performs a binary Not. The second argument is the length of the number you wish to perform Not on in bits. |
Function | Returns | Description |
---|---|---|
toString(N,N) |
![]() |
See Expression 2 String. |