Skip to content

mod - Calculate division remainder using Modulus

The mod function returns the modulus (remainder) of number divided by divisor.

Syntax

Like many functions in DataPrime, mod supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

mod(number: number, divisor: number): number
number: number.mod(divisor: number): number

Arguments

NameTypeRequiredDescription
numbernumbertrueThe number whose modulus we seek to find
divisornumbertrueThe modulo value we will use, for example a divisor of 2 is the equivalent of calculating number % 2

Example - Check if a value is even or odd

If we have a numeric value val, we can use modulus to test if the number is odd or even.

create is_even from (mod(val, 2) == 0)
create is_even from (val.mod(2) == 0)

This will set is_even to true if the number is even (if the division remainder of 2 is 0), or false if the number is odd.