LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DBL to I32

Solved!
Go to solution

Hi,

I would appreciate if someone could answer this question. Why 1 is divided by 2, the answer is 0 if the answer uses I32 data type? But 3 is divided by 2, the answer is 2 if the answer uses I32 data type?  5 is divided by 2, the answer is 2 if the answer uses I32 data type?

Thank you,

Steve

0 Kudos
Message 1 of 4
(4,467 Views)

Because LabVIEW rounds x.5 to the even number. While I agree this is incredibly stupid and annoying, it gets its roots from IEEE 754: http://en.wikipedia.org/wiki/Rounding (search IEEE on that page).

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
0 Kudos
Message 2 of 4
(4,461 Views)
Solution
Accepted by topic author Shijie

As stated, rounding goes to the nearest even number when at X.5.

 

If you are dividing integers (and keeping with integers), you really should be using the Quotient & Remainder function instead.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(4,452 Views)

Its called "Bankers rounding" and the correct IEEE 754 implementation since the divide is done as Floating point.  However, if you want to stay in integer math use logical shift to multiply or divide by powers of two

1!.PNG


"Should be" isn't "Is" -Jay
Message 4 of 4
(4,444 Views)