Why mod(19, nRun) where nRun is 19, is not equal to 0?
Mostra commenti meno recenti
I found a strange behavior regarding the matlab modulus function where I hope the Mathworks community is able to help explain and provide suggestions on how to overcome this.
Why is mod(19,nRun), where nRun = 19, is not 0 and instead output 19?

1 Commento
"Why mod(19, nRun) where nRun is 19, is not equal to 0?"
Actually it is. Lets try it right now:
mod(19,19)==0
"I found a strange behavior regarding the matlab modulus function..."
What you found has nothing to do with the MOD function.
It is caused by the fact that your nRun is not exactly equal to 19. Lets try it right now:
yl = 1 - 0.9999; % not 0.0001 (this does not exist)
lpr = yl * 500; % not 0.05
nrpl = 1/lpr; % not 20
nr = nrpl - 1; % not 19
nr-19 % nope, definitely not 19
This is a completely expected result or arithmetic using binary floating point numbers:
This is worth reading as well:
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!