Skip to content

Operator Mod (Modulus)


Finds the remainder from a division operation

Syntax

` declare operator Mod ( byref lhs as integer, byref rhs as integer ) as integer

`

Usage

` result = lhs Mod rhs

`

Parameters

lhs

The left-hand side dividend expression.

rhs

The right-hand side divisor expression.

Return Value

Returns the remainder of a division operation.

Description

Operator Mod (Modulus) divides two Integer expressions and returns the remainder. Float numeric values are converted to Integer by rounding up or down.

Neither of the operands are modified in any way.

This operator can be overloaded for user-defined types.

Examples

start GeSHi

vb
Print 47 Mod 7
Print 5.6 Mod 2.1
Print 5.1 Mod 2.8

end GeSHi

Output:

5
0
2

This is because:

  • 47 divided by 7 gives a remainder of 5
  • 5.6 is rounded to 6 while 2.1 is rounded to 2. This makes the problem 6 MOD 2 which means 6 divided by 2 which gives a remainder of 0
  • 5.1 is rounded to 5 while 2.8 is rounded to 3. This makes the problem 5 MOD 3 which means 5 divided by 3 which gives a remainder of 2

Dialect Differences

  • In the -lang qb dialect, this operator cannot be overloaded.

Differences from QB

  • None

See also

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft