Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Controls Guy on April 22, 2021, 05:11:56 PM
-
I have
MATH V0 "TICKus() % 5"
and I got 65535 and 65532 in V0, which is written nowhere else in logic and there's no HMI. How can a modulo operation return a value less than zero (if it's actually thinking -1 or -4), or a value greater than the divisor??
-
Modulo with negative numbers gives strange results (negative remainder).
Best to convert it to positive, although not sure what happens when it's -2147483648
ABS(TICKus()) % 5
-
However, realize that TICKus() will go from +2147483647 (0x7FFFFFFF) to -2147483648 (0x80000000) in 1 microsecond
-
Ah, even though 32-bit I was assuming unsigned, not sure why.
-
Just generating a random. ABS() would work or I can just use (TICKus() & 0x8FFF)%5.
Any better thoughts on an RNG?
-
Why not use RANDINT() or RANDREAL()?
-
Cause of not knowing about them? ;D