LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i get a remainder of division in cvi (i.e. the modulus operatror in C %)?

i'm looking to get the remainder of division in CVI. I can do it in C with the modulus operator (%) , but CVI doesn't recognize it. how can this be accomplished?

thanx chris h.
0 Kudos
Message 1 of 4
(5,069 Views)
I'm confused. The modulus operator is supported in CVI. Try this:

int x;

x = 5 % 2;

That should work fine in CVI, it does for me. Also, the ANSI C library provides the fmod() function for this.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 4
(5,069 Views)
thanx for answering, ok that does work. now how do i get the first part. the part that is thrown away by %

5 % 2 = 1 & a 2 is thrown away

or how about

139/2 = 69 mod 1; i need the 69 & the 1

thanx chris h.
0 Kudos
Message 3 of 4
(5,069 Views)
Yea, obviously the operator can only output one thing which is the modulus for the mod operator (%). If you want the division result, use the divide operator. If you are working with integers, that would be:

int a = 139;
int b = 2;
int mod, div;

mod = a % b;
div = a / b;

If a and b are floating point numbers, you would want to put a floor call into the division statement, like:

div = floor (a / b);

Chris
0 Kudos
Message 4 of 4
(5,069 Views)