topic Re: How to round mathematical (not IEEE) in LabVIEW
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671976#M596153
<P>The reason you need IEEE for rounding is that there is no real representation for x.5 in floating point. You basically always get x.5 +/- epsilon. If it really matters, you could shift your numbers by machine epsilon.</P>Tue, 16 Aug 2011 12:42:48 GMTTaki19992011-08-16T12:42:48ZHow to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671950#M596147
<P>Hello,</P>
<P>i have a number that should be rounded to the next integer.</P>
<P>I found that there is a IEEE... that described what to do for rounding.</P>
<P>But the mathematic-rounding is different.</P>
<P> </P>
<P>The problem is only a x.5 values (1.5 / 2.5 / 3.5 / 4.5).</P>
<P>Labview is rounding to the next even integer - but the correct mathematical way is to round it always up if .5.</P>
<P> </P>
<P>How can i do this in Labview?</P>
<P> </P>
<P>Thanks for help</P>Tue, 16 Aug 2011 12:24:34 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671950#M596147OnlyOne2011-08-16T12:24:34ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671976#M596153
<P>The reason you need IEEE for rounding is that there is no real representation for x.5 in floating point. You basically always get x.5 +/- epsilon. If it really matters, you could shift your numbers by machine epsilon.</P>Tue, 16 Aug 2011 12:42:48 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671976#M596153Taki19992011-08-16T12:42:48ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671986#M596157
<P>Hi Taki,</P>
<P> </P>
<P>there is a "real" representation of 0.5 in a floating point mantissa - as it is the same as 1/2 you really only need one bit of accuracy for this...</P>
<P> </P>
<P>@OnlyOne:</P>
<P>If you really need to round always upwards:</P>
<P><IMG src="http://forums.ni.com/t5/image/serverpage/image-id/50488i5AF2410F1E1544CA/image-size/original?v=mpbl-1&px=-1" border="0" alt="check.png" title="check.png" align="middle" /></P>
<P>(Any problems because of sign(x) are up to you...)</P>
<P> </P>Tue, 16 Aug 2011 12:54:34 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1671986#M596157GerdW2011-08-16T12:54:34ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672000#M596160
<BLOCKQUOTE><HR /><LI-USER uid="31575"></LI-USER> wrote:<BR />
<P>Hello,</P>
<P>i have a number that should be rounded to the next integer.</P>
<P>I found that there is a IEEE... that described what to do for rounding.</P>
<P>But the mathematic-rounding is different.</P>
<P> </P>
<P>The problem is only a x.5 values (1.5 / 2.5 / 3.5 / 4.5).</P>
<P>Labview is rounding to the next even integer - but the correct mathematical way is to round it always up if .5.</P>
<P> </P>
<P>How can i do this in Labview?</P>
<P> </P>
<P>Thanks for help</P>
<HR /></BLOCKQUOTE>
<P>Hi OnlyOne,</P>
<P> </P>
<P>It is standard practice to round to the nearest even value when rounding with a 0.5 decimal place, although that's contrary to what I was taught in school! I recently read about this operation in Engineering Mathematics by K.A Stroud, so I'm unsure about whether or not this applies just to engineering. However, I've managed to indirectly derive the functionality you want through this VI below:</P>
<P> </P>
<P style="text-align: center;"><IMG src="http://forums.ni.com/t5/image/serverpage/image-id/50486i2733E06BF6A04FBD/image-size/original?v=mpbl-1&px=-1" border="0" alt="Rounding.png" title="Rounding.png" align="center" /></P>
<P style="text-align: center;"> </P>
<P style="text-align: left;">This method takes away 0.49 from the input double and uses the <STRONG>Round to Positive Infinity</STRONG> VI to round the input values according to your requirements.</P>
<P> </P>
<P>I hope that you find this helpful; it'd be nice to find out whether or not this gives you the precision in your values that you're wishing for as well as if we need to find a better implementation!</P>Tue, 16 Aug 2011 12:56:16 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672000#M596160Alex.T2011-08-16T12:56:16ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672010#M596163
<P>hehe, currently i do the same by + 0.1 <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>
<P>I thought there is also a lv-function to round correct in school-style.</P>Tue, 16 Aug 2011 12:56:06 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672010#M596163OnlyOne2011-08-16T12:56:06ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672018#M596166
<P>Hi OnlyOne,</P>
<P> </P>
<P>"to round correct in school-style."ï»¿</P>
<P>The problem is: <STRONG>school style</STRONG> is not the same as <STRONG>correct rounding</STRONG> <img id="smileywink" class="emoticon emoticon-smileywink" src="https://forums.ni.com/i/smilies/16x16_smiley-wink.gif" alt="Smiley Wink" title="Smiley Wink" /></P>
<P>And there were reasons to define <A href="http://en.wikipedia.org/wiki/Rounding#Tie-breaking" target="_self">bankers' rounding</A> in IEEE754 standard!</P>Tue, 16 Aug 2011 13:00:17 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672018#M596166GerdW2011-08-16T13:00:17ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672024#M596168
<P>But when someone writes 2.5 on paper then it is really a 2.5 and not any epsilon values behind it.</P>
<P> </P>Tue, 16 Aug 2011 13:01:21 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672024#M596168OnlyOne2011-08-16T13:01:21ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672044#M596175
<P>Hi OnlyOne,</P>
<P> </P>
<P>when someone write 2.5 in a computer spreadsheet someone also gets 2.5! (See above.)</P>
<P>The problem starts with any fraction that is not representable by multiples of two!</P>
<P> </P>
<P>"But when someone writes ... on paperï»¿"</P>
<P>When someone writes on paper he isn't aware of problems arising from rounding errors inherent to number representation on modern computers...</P>Tue, 16 Aug 2011 13:13:10 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672044#M596175GerdW2011-08-16T13:13:10ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672052#M596177
<BLOCKQUOTE><HR /><LI-USER uid="16916"></LI-USER> wrote:<BR />
<P>Hi Taki,</P>
<P> </P>
<P>there is a "real" representation of 0.5 in a floating point mantissa - as it is the same as 1/2 you really only need one bit of accuracy for this...</P>
<P> </P>
<HR /></BLOCKQUOTE>
<P><BR />Indeed, you are right. Too early in the morning for me to suppress my normal FP accuracy reflex. <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>
<P>Sorry about the confusion.</P>Tue, 16 Aug 2011 13:18:49 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672052#M596177Taki19992011-08-16T13:18:49ZRe: How to round mathematical (not IEEE)
https://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672064#M596179
<BLOCKQUOTE><HR /><LI-USER uid="31575"></LI-USER> wrote:<BR />
<P>But when someone writes 2.5 on paper then it is really a 2.5 and not any epsilon values behind it.</P>
<HR /></BLOCKQUOTE>
<P> </P>
<P>And computers don't work on paper. What's your point? Computers don't store numbers the way you write them on paper. That's a fact. It's been a fact since computers were invented. You, as the programmer need to understand this and deal with it, or just stick with a paper and pencil. The others here have tried to explain it and offered suggestions. Yet you insist that "school rounding" is the "correct" rounding. There is no correct rounding. There are simply rounding rules. Did you read the link Gerd pointed you to?</P>Tue, 16 Aug 2011 13:24:11 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-mathematical-not-IEEE/m-p/1672064#M596179smercurio_fc2011-08-16T13:24:11Z