Floordiv()

From TinyMUX
Jump to navigation Jump to search

Description

FUNCTION: 20px-Function.png floordiv(number1,number2)

Returns the integer quotient from dividing number1 by number2.

However, integer division for the case where either integer1 or integer2 is negative is defined in a specific way -- by choosing the largest integer that is less than or equal to the algebraic quotient. If integer1 and integer2 are the same sign, then idiv() and floordiv() are equivalent.

For example, division of -9 by 5 would give -2 by this definition instead of -1. idiv() would return -1. floordiv() would return -2. The floordiv() function goes with the mod() function.

floordiv(x,y)*y + mod(x,y) ==> x

Related Topics: fdiv(), iadd(), idiv(), imul(), isub(), mod(), remainder().

Examples

> say floordiv(15,3)
You say "5"
> say floordiv(16,3)
You say "5"
> say floordiv(17,3)
You say "5"
> say floordiv(18,3)
You say "6"
> say floordiv(-17,3)
You say "-6"


(--Soylent 01:26, 3 December 2005 (EST))