mod function return wrong answer?

5 vues (au cours des 30 derniers jours)
Hiroaki Yamamoto
Hiroaki Yamamoto le 4 Juil 2020
Commenté : madhan ravi le 5 Juil 2020
How can I make sure mod(a,b) returns value less than b, without explicitly calling min( mod(a,b), b )?
mod( -eps, 1 ) = 1 when eps ~ 10^-17.
Numerical accuracy is not an issue, but I need mod( a, 1 ) be less than 1.
  3 commentaires
madhan ravi
madhan ravi le 5 Juil 2020
Modifié(e) : madhan ravi le 5 Juil 2020
Sindar I suggest moving your comment as an answer
Hiroaki Yamamoto
Hiroaki Yamamoto le 5 Juil 2020
I expected mod( a, m ) < m (less than m),
but numerically mod(a, m) <= m (less than or equal to m) is the result when a = -1e-17 and m = 1.
If, internally, 1 - 10^-17 = 1 is calculated and returned, I think 0 is the mathematically correct return value rather than 1.

Connectez-vous pour commenter.

Réponses (1)

madhan ravi
madhan ravi le 5 Juil 2020
>> mod( -eps, 1 ) < 1
ans =
logical
1
  4 commentaires
Hiroaki Yamamoto
Hiroaki Yamamoto le 5 Juil 2020
My question is, mathematically which of the following is correct or intended to be implemented.
1) mod(a, m) < m
or
2) mod(a, m) <= m.
Practically, I found mod(a,m) = m can happen and I do explicit check and avoid problems caused by the case mod(a,m) = m.
madhan ravi
madhan ravi le 5 Juil 2020
Practically speaking it depends on what m is.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by