Skip to content
jschanker edited this page Feb 16, 2016 · 1 revision

Math functions

The code fragments below assume that generic_number_variable was previously set to an integer (or any decimal number where sensible) according to Variables. E.g.,

set generic_number_variable to 42

If one of these phrases doesn't seem to work in a larger expression or statement, try surrounding the entire code phrase with parentheses.

Remainder

number-functions-remainder

remainder of generic_number_variable divided by 10
  • 10 can be replaced with a variable storing an integer.

Numeric properties/divisibility

number-relations-even-odd-prime-whole-positive-negative-divisible-by

generic_number_variable is even
generic_number_variable is odd
generic_number_variable is prime
generic_number_variable is whole
generic_number_variable is positive
generic_number_variable is negative
generic_number_variable is divisible by 10

Square root and absolute value

number-sqrt-abs

square root generic_number_variable
absolute generic_number_variable
  • sqrt generic_number_variable also works.
  • generic_number_variable can be replaced with any numeric literal or even if generic_number_variable were set in the usual Ruby way via the assignment operator.

Changing number stored by variable

number-change

This can be accomplished via the following:

increase generic_number_variable by 10

Other options include e.g.,

decrease generic_number_variable by some_other_number_variable
multiply generic_number_variable by 10
divide generic_number_variable by some_other_number_variable
Clone this wiki locally