Appearance
Numbers
There is no difference in terms of behavior between GreyScript and MiniScript.
All numeric values in MiniScript are stored in standard full-precision format (also known as “doubles” in C-derived languages). Numbers are also used to represent true (1) and false (0). Numeric literals are written as ordinary numbers, e.g. 42, 3.1415, -0.24.
Source: MiniScript manual
Operations
gs
// addition
a = 1 + 1 // numeric sum of 1 and 1 - results in 2
// subtraction
a = 1 - 1 // 1 subtracted by 1 - results in 0
// multiplication
a = 2 * 2 // 2 multiplied by 2 - results in 4
// division
a = 2 / 2 // 2 divided by 2 - results in 1
// modulo
a = 2 % 1 // remainder after dividing 2 by 1 - results in 0
// power
a = 2 ^ 4 // 2 raised to the power of 4 therefore - results in 16
// logical and
a = true and false // results in false (2) since one of the values is false
// logical or
a = true or false // results in true (1) since one of the values is true
// negation
a = not true // results in false (0)
// equality
a = 1 == 2 // returns true (1) if two numbers are equal otherwise false (0) - results in false (0)
// inequality
a = 1 != 2 // returns true (1) if two numbers are inequal otherwise false (0) - results in true (1)
// greater than
a = 1 > 2 // returns true (1) if the first number is greater than the second number otherwise false (0) - results in false (0)
// greater than or equal
a = 1 >= 2 // returns true (1) if the first number is greater than or equal to the second number otherwise false (0) - results in false (0)
// less than
a = 1 < 2 // returns true (1) if the first number is less than the second number otherwise false (0) - results in true (1)
// less than or equal
a = 1 <= 2 // returns true (1) if the first number is less than or equal to the second number otherwise false (0) - results in true (1)
Isa
Beside of using typeof, to determine if a variable is a number, you can also use isa.
gs
myVariable = 42
print(myVariable isa number) // prints 1
Extend type
It is possible to extend your own methods to the number type.
gs
number.add = function(otherNum)
return self + otherNum
end function
print((10).add(10)) // prints 20