Math
Most simple math operations are doable with the operation
command. It takes in an odd number of parameters, alternating between values (which can be either direct numbers or variable names) and operators. Operators are given as plain names with spaces between words. The supported operators are:
Budgie Syntax
Common Equivalent
and
&&
decrease by
-=
divide
/
divide by
/=
equal to
=
equals
==
greater than
>
greater than or equal to
>=
increase by
+=
less than
<
less than or equal to
<=
minus
-
mod
%
multiply by
*=
not
!
not equal to
!=
or
||
plus
+
times
*
Recall that parenthesis are required for arguments with spaces: including operator aliases.
The parenthesis
command is also commonly used with math. It takes a single argument and wraps it in ()
parentheses.
In C#:
In Python:
Number Types
Some languages recognize a difference between integers, doubles, floats, and other number types. Some do not. For feature parity between other languages, Budgie recognizes only int
and double
as valid number types. float
, long
, ushort
, and so on are not supported.
Number Conversions
When you have a double
and need an int
, use the math as int
command to truncate and convert to an int
. It behaves similarly to math floor
but returns an int
instead of a double
.
In C#:
int rounded = (int)3.5;
In Python:
rounded = math.floor(3.5)
Native Commands
All supported languages provide some amount of built-in math operations beyond the simple arithmetic operators. These are typically encapsulated in some kind of global Math
object and/or system namespace that contains simple functions and constants.
Budgie abstracts away the differences in these "native" commands. For example:
In C#:
Math.Max(foo, bar)
In Python:
max(foo, bar)
All possible native math commands are given below.
Budgie Syntax
Common Equivalent
math absolute
math.abs()
math ceiling
math.ceil()
math floor
math.floor()
math max
math.max()
math min
math.min()
math power
math.pow()
Last updated