mod: Modulo-operator with near-equality

Description Usage Arguments Details Value Alternative usage Note

Description

The '%%' operator calculates the modulo, but sometimes has rounding errors, e.g. "(9.1/.1) %% 1" gives ~ 1, instead of 0.
Comparable to what all.equal does, this operator has some tolerance for small rounding errors.
If the answer would be equal to the divisor within a small tolerance, 0 is returned instead.

Usage

1
`%mod%`(x, y, tolerance = sqrt(.Machine$double.eps))

Arguments

x, y

numeric vectors, similar to those passed on to %%

tolerance

numeric, maximum difference, see all.equal. The default is ~ 1.5e-8

Details

For integer x and y, the normal %%-operator is used

Value

identical to the result for %%, unless the answer would be really close to y, in which case 0 is returned

Alternative usage

x %mod% y may be most useful in practice

Note

To specify tolerance, use the call `%mod%`(x,y,tolerance)

The precedence for %mod% is the same as that for %%


EmilBode/EmilMisc documentation built on Feb. 24, 2020, 4:11 p.m.