Function Math Reals Class

ModAlt

"Modulo (Alternate Definition)" or "Modulus" or "Remainder" Floating-point modulus of real numbers.

Signature (Visual Basic / VBA)

Public Function ModAlt( _
      ByVal vX As Variant _
    , ByVal vY As Variant _
    ) As Variant

Code Examples

    ModAlt(0, 3) = 0
    ModAlt(1, 3) = 1
    ModAlt(2, 3) = 2
    ModAlt(3, 3) = 0
    ModAlt(4, 3) = 1
    ModAlt(-1, 3) = 2
    ModAlt(-2, 3) = 1
    ModAlt(-2, -3) = -2
    ModAlt(2, -3) = -1
    Y = 4:
      *   *   *|  *   *   *
     *   *   * | *   *   *
    *   *   *  |*   *   *
    ---*---*---*---*---*---
               |
    Y = -4:
               |
               |
               |
    ---*---*---*---*---*---
      *   *   *|  *   *   *
     *   *   * | *   *   *
    *   *   *  |*   *   *
    X - Y * Int(X / Y)
    X - Y * Floor(X / Y)

Parameters

Parameter Description
vX See the definition. Function returns Null if vX is Null or cannot be fixed up to a number.
vY See the definition. Function returns Null if vY is Null or cannot be fixed up to a number.

Notes & Version History

Note Differs from the ModStd function when X is negative and Y is positive. We believe that this definition of the modulo function is much more widely accepted than the other definition (which is similar to the one that Microsoft implements in all of their language products).