mod (modulo, fmod) in interval arithmetic

43 Views Asked by At

How can I calculate the modulo of a number given as interval?

I've tried with mpmath library, but that doesn't seem to work:

import mpmath
def mod(a: float, b: float, eps = 1e-9) -> float:
    a = mpmath.iv.mpf([a-eps, a+eps])
    b = mpmath.iv.mpf([b-eps, b+eps])
    return mpmath.fmod(a, b)

x = mod(0.2, 0.333333333))  # ValueError: can only create mpf from zero-width interval

I'm not bound to that library, just want to ensure that my calculations don't suffer from numerical issues.

0

There are 0 best solutions below