LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Floor (roundind toward -infinity) error

Hi everybody,

 

I just found a surprising error in Labview 2013. I want to get the interger part of the division of 2 float numbers: after the division I use the "floor" vi in the numerical palette. In some situations (with numbers below 1) this interger part is lower by 1 to what is should be. Example:

300m / 25m = 12.00 (division output)

floor(12.00) = 11.00

 

It seems to work only when both initial number are <1 and not in every configuration. I was wondering if it is some epsilon machine error in the calculation of the division

 

I'll use another solution for my calculation, but I think it may be corrected.

 

Regards.

0 Kudos
Message 1 of 5
(3,199 Views)

Hi Nico,

 

I was wondering if it is some epsilon machine error in the calculation of the division

Yes.

For clarity: set the display format of your floats to "%.20g" to see the reason of this "unexpected result"!

check.png

 

You will find a lot of threads handling rounding issues with floating point numbers, here in the forum as well as on Wikipedia!

 Side note: why don't you use Quotient&Remainder function? It gives the same (flaky) result when used with DBLs…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(3,193 Views)

Didn't went that far in looking at decimals.

Quotient and remainder function has the same problem yes.

 

I'll try to dig the forums to find solutions, but I think the most obvious is to multiply both number by 10^n with n chosen so that the number I get are intergers (no decimal part). And then I'll use the quotient and remainder function.

 

 

0 Kudos
Message 3 of 5
(3,166 Views)

Hi Nico,

 

the most obvious is to multiply both number by 10^n

Yes.

 

Didn't went that far in looking at decimals.

You should. With floats: always…

(For background see IEEE754, IEEE854)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(3,160 Views)

Hum. Finally, I worked on mantissa and exponent, and added epsilon to division of the 2 mantissa. Seems to work without side effect. For the moment....

 

Many thanks for your help Gerd 🙂

0 Kudos
Message 5 of 5
(3,149 Views)