LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mod(x,y) and Quotient & Remainder.vi yield different results

Is it normal that the mod(x,y) function doesn't yield the same results as the Quotient & Remainder.vi when x is negative?

For instance, if you use the Quotient & Remainder.vi with x=-3.7 and y=1, the results are:

x-y*floor(x/y)=0.3 and floor(x/y)=-4

which is consistent and also what I expected.

However, if you compute mod(x,y), the result is -0.7, whereas the floor(x/y) function yields -4, which is inconsistent.

Shouldn't mod(x,y) be equivalent to x-y*floor(x/y)?

Thanks if you can help.
0 Kudos
Message 1 of 5
(3,205 Views)
Seems like mod(x/y) has a bug when used with negative numbers. mod(-3.7/1) uses a floor of -3 instead of -4, so the remainder is -0.7 instead of 0.3. Don't use this, instead use the Q&R vi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 5
(3,186 Views)
I am not aware of a "mod(x,y)" function in LabVIEW.

Could you tell us which mod(x,y) function you are comparing?
0 Kudos
Message 3 of 5
(3,186 Views)
It is the mod(x,y) when using formula node.
Apparently, it must not be used with negative numbers
0 Kudos
Message 4 of 5
(3,179 Views)
> Don't use this, instead use the Q&R vi.

Well, since I wanted to use it in a formula node, I just typed x-y*floor(x/y) instead of mod(x,y). But I don't get why mod(x,y) is not simply defined like that.

Thanks anyway.
0 Kudos
Message 5 of 5
(3,171 Views)