LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding Values

If your concerned about speed, The divide in mine can be replaced with a bit shift in the integer case. Also if the inputs were made constant, instead of controls then constant folding should remove the first divide (assuming the version of labview is new enough to have constant folding). And the select node in yours will likely become a hard to predict branch when compiled (unless labview's compiler is smarter than I think it is) which will slow things down a more than a divide (at least in a modern desktop cpu). You could replace the select with a
"Boolean to (0,1)" which I would be surprised if it had a branch in it, but I think it would still be slower.

As for the rounding 250 will normally round up to 500 unless your using a unbiased routing like bankers' rounding. Which the int method in the formula nodes uses (compare int(0.5); and int(1.5); ),but the round method in mathscript should match up with ours. But I don't know which "Round to nearest" your talking comparing against though. An unbiased rounder is likely overkill unless your doing a statistical analysis.


Here's a version for 8.0.1
0 Kudos
Message 11 of 14
(1,129 Views)
Here's what I would do.... 😄
 
 

Message Edited by altenbach on 03-08-2007 03:16 PM

0 Kudos
Message 12 of 14
(1,122 Views)
*smack head*
I missed the round to nearest node. That uses bankers' rounding (round to even) if anyone cares.
0 Kudos
Message 13 of 14
(1,118 Views)
Hello all.
Now that altenbach and GerdW posted the same solutions, I am convinced that this is the best way to handle it.

Sorry that I cannot understand the discussion about "banker's rounding": Every good math book defines, that x.5 values are to be rounded to the nearest even integer. LabVIEW, CVI, (and other environments) handle this accordingly (i.e. correctly).

If I'd prefer the "classic rounding rules" that we typically learn in school, I'd check the fractional part for equality to 0.5  and  if it is, round to +Inf, else to the nearest integer.
Regards, Guenter
0 Kudos
Message 14 of 14
(1,111 Views)