Skip to content

Modern Math FloorDiv

Paul Squires edited this page Oct 19, 2026 · 6 revisions

Home › Math Library › Math Library › FloorDiv

FloorDiv

Divides whole numbers rounding towards negative infinity, so FloorDiv(-7, 2) is -4.

Syntax

FloorDiv( byval a as T, byval b as T ) as T

Notes

  • The \ operator truncates towards zero, matching C: -7 \ 2 is -3. This gives -4.
  • It is the division that pairs with FloorMod, so that FloorDiv( a, b ) * b + FloorMod( a, b ) is a for every sign combination.
  • EuclidDiv is the third convention, whose remainder is always non-negative.

Examples

#import "std/numeric"
using numeric

dim as int32 a = -7, b = 2

print FloorDiv( a, b )       '' -4 -- towards negative infinity
print a \ b                  '' -3 -- the built-in truncates towards zero

'' The identity that makes the pair usable
print FloorDiv( a, b ) * b + FloorMod( a, b ) '' -7

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally