LabWindows/CVI Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
vix

Add FP_Max() and FP_Min() functions

Status: New

Comparison between floating point numbers is best done using FP_Compare() - see CVI help for details.

Often you need to choose the maximum (or the minimum) of the two floating point numbers, and the most common approach is:

if (a > b) {

choose a

} else {

choose b

}

If you use FP_Compare instead of ">" you'll notice that FP_Compare is much slower than ">" (because it involves calculation of the ratio between the two numbers). This is extremely evident if you have to choose the maximum of several couples of numbers.

I think that the maximum (or the minimum) between two floating point numbers could be found in a more effective way, comparing the exponents of IEEE representation (for example), and calculate the ratio only if the exponents are equal.

For this reason I suggest two new functions FP_Max() and FP_Min() that would much more performant than the easy approach.

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0