Bug with mod(x,y) function?

Sandbo
Posts: 21
Joined: 2017-05-10
Location: Canada

Hi,

With Igor 6.37,
I was trying to use the mod function but it turns out funny, so I checked it step by step and found this:

print (mod(3.8e-6*1.2*1e9,2*8))
  16

where

print 3.8e-6*1.2*1e9/(2*8)
  285

Checking on Wolfram, the mod does give zero.
https://www.wolframalpha.com/input/?i=(mod(3.8e-6*1.2*1e9,2*8))
Am I missing something?

PS: Just tested in Igor 7.0.8, the same happens.


[ last edited April 3, 2018 - 12:59 ]
tony
Posts: 162
Joined: 2007-08-28
Location: Canada

printf "%0.20f\r", 3.8e-6*1.2*1e9/(2*8)
  284.99999999999994315658printf "%0.20f\r",  (mod(3.8e-6*1.2*1e9,2*8))
  15.99999999999909050530printf "%0.20f\r",  (mod(3.8*1.2*1e3,2*8))
  0.00000000000000000000


Sandbo
Posts: 21
Joined: 2017-05-10
Location: Canada

tony wrote:
printf "%0.20f\r", 3.8e-6*1.2*1e9/(2*8)
  284.99999999999994315658printf "%0.20f\r",  (mod(3.8e-6*1.2*1e9,2*8))
  15.99999999999909050530printf "%0.20f\r",  (mod(3.8*1.2*1e3,2*8))
  0.00000000000000000000

Thanks for the idea, sounds like a precision issue.
In my case I can modify it to have 3.8, that should solve it for now.

Update: Not really, and I found another problem.
The above were a proc for a panel setVariable action entry.
1. If I type in a number 3.8e-5, the mod() returns zero and it works.
2. If I scroll using mouse from 3.7e-5 to 3.8e-5 (incre is 1e-6), the mod() returns something funny and cause problem.


[ last edited April 3, 2018 - 13:32 ]
jjweimer
jjweimer's picture
Posts: 1325
Joined: 2007-08-14
Location: United States

print (mod(round(3.8*10^-6*1.2*1e9),2*8))
  0
print (mod(round(3.8*10e-6*1.2*1e9),2*8))
  0

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


Sandbo
Posts: 21
Joined: 2017-05-10
Location: Canada

jjweimer wrote:
print (mod(round(3.8*10^-6*1.2*1e9),2*8))
  0
print (mod(round(3.8*10e-6*1.2*1e9),2*8))
  0

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


Thanks a lot, this has solved it completely (even with scrolling).


Back to top