Comment on page

# 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.operation : foo times 2

operation : foo (decrease by) bar times { parenthesis : { operation : bar minus 3 } }

variable : bar double { operation : foo (divide by) 3 plus 4 times foo }

In C#:

foo *= 2;

foo -= bar * (bar - 3);

double bar = foo /= 3 + 4 * foo;

In Python:

foo *= 2

foo -= bar * (bar - 3)

bar = foo /= 3 + 4 * foo

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.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`

.variable : rounded int { math as int : 3.5 }

- In C#:
`int rounded = (int)3.5;`

- In Python:
`rounded = math.floor(3.5)`

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:

math max : foo bar

- 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 modified 4yr ago