04-06-2017 11:50 AM
I opened a service request for this bug, also.
It seems a single precision shift register inherits its exponent from some combination of the input controls but not itself, and therefor saturates. Originally I noticed this in LabVIEW FPGA using the Xilinx floating point coregen primitives. It also occurs with the regular LabVIEW single precision primitives in FPGA, and ultimately in Windows as shown below. I haven't simplified it any more, but a multiply accumulate is a pretty common function to use.
04-06-2017 12:05 PM
Not that I know the answer...
0.0000004 can not be represented in binary so LV uses the closest value.
Sinlge >>> 0.000000400000004674438968
Doulbe >>> 0.000000399999999999999981
Ben
04-06-2017 12:11 PM - edited 04-06-2017 12:16 PM
Ben,
For sure that is understood. It is interesting behavior. With the release of single precision floats to LV FPGA, more issues may arise.
Here is 2 more test cases.
Edit: First image had non-matching values in controls.
04-06-2017 12:22 PM
This is to be expected. A single-precision value doesn't have enough resolution to store 8.0000004 (8+0.004*0.0001), so the 0.0000004 gets cut off. Try it out - paste that value into a single-precision control, and you'll see that you lose the small fractional portion.
04-06-2017 01:27 PM
Just for a bit more proof: storing the value 8 requires an exponent of at least 3. A single-precision value has 23 bits for the number, so if we set the lowest bit to 1, it will have a value of 2^-20 (because 23-3=20), or approximately 9.537E-7. So, a single-precision number can't store any value between 8 and 8.0000009537; any value in that range gets rounded down to 8.
04-06-2017 02:18 PM
There is no bug, just a limitation of floating point numbers if the mantissa does not have an infinite number of bits.
An illustrative example if the definition of machine epsilon, so once the ratio of increment and sum is less than epsilon, the addition will no longer increase the sum. Machine epsilon is even in the palette!
You code is a crude way to estimate the value of machine epsilon, nothing more.