Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

08-16-2011 07:24 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hello,

i have a number that should be rounded to the next integer.

I found that there is a IEEE... that described what to do for rounding.

But the mathematic-rounding is different.

The problem is only a x.5 values (1.5 / 2.5 / 3.5 / 4.5).

Labview is rounding to the next even integer - but the correct mathematical way is to round it always up if .5.

How can i do this in Labview?

Thanks for help

08-16-2011 07:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

08-16-2011 07:47 AM - edited 08-16-2011 07:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi Taki,

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...

@OnlyOne:

If you really need to round always upwards:

(Any problems because of sign(x) are up to you...)

Best regards,

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

08-16-2011 07:52 AM - edited 08-16-2011 07:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@OnlyOne wrote:

Hello,

i have a number that should be rounded to the next integer.

I found that there is a IEEE... that described what to do for rounding.

But the mathematic-rounding is different.

The problem is only a x.5 values (1.5 / 2.5 / 3.5 / 4.5).

Labview is rounding to the next even integer - but the correct mathematical way is to round it always up if .5.

How can i do this in Labview?

Thanks for help

Hi OnlyOne,

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:

This method takes away 0.49 from the input double and uses the **Round to Positive Infinity** VI to round the input values according to your requirements.

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!

08-16-2011 07:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

hehe, currently i do the same by + 0.1 🙂

I thought there is also a lv-function to round correct in school-style.

08-16-2011 07:58 AM - edited 08-16-2011 08:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi OnlyOne,

"to round correct in school-style."

The problem is: **school style** is not the same as **correct rounding**

And there were reasons to define bankers' rounding in IEEE754 standard!

Best regards,

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

- Tags:
- IEEE754

08-16-2011 08:01 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

But when someone writes 2.5 on paper then it is really a 2.5 and not any epsilon values behind it.

08-16-2011 08:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi OnlyOne,

when someone write 2.5 in a computer spreadsheet someone also gets 2.5! (See above.)

The problem starts with any fraction that is not representable by multiples of two!

"But when someone writes ... on paper"

When someone writes on paper he isn't aware of problems arising from rounding errors inherent to number representation on modern computers...

Best regards,

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO

08-16-2011 08:18 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@GerdW wrote:

Hi Taki,

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...

Indeed, you are right. Too early in the morning for me to suppress my normal FP accuracy reflex. 🙂

Sorry about the confusion.

smercurio_fc

Knight of NI

08-16-2011 08:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@OnlyOne wrote:

But when someone writes 2.5 on paper then it is really a 2.5 and not any epsilon values behind it.

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?