#### Do you have a question? Post it now! No Registration Necessary

Re: ROUND function source for IEEE-754

Assuming you are talking about C, from N869:

7.12.9.6 The round functions

Synopsis

[#1]

#include <math.h>

double round(double x);

float roundf(float x);

long double roundl(long double x);

Description

[#2] The round functions round their argument to the nearest

integer value in floating-point format, rounding halfway

cases away from zero, regardless of the current rounding

direction.

Returns

[#3] The round functions return the rounded integer value.

You can build your ROUND function from this with some

multiplications and divisions.

--

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

We've slightly trimmed the long signature. Click to see the full one.

Re: ROUND function source for IEEE-754

This function will round a float to the precision given by 'precision'. If

precision is 2 then 525.345 will give 525.35 and with a precision of -2,

ROUND( 9856.0 , -2) will give 9900.

I already found the code but it's a lot of div. and mul.. I was hoping that

there is a smart way to do it when the number format ( such as IEEE-754) is

known.

Gerard

Re: ROUND function source for IEEE-754

that

is

The IEEE format is a binary format. There is no speedy shortcut to decimal

rounding of binary fractions. Even as simple as 0.1 decimal is an unending

fraction in binary (0.0001100110011001100...).

Would you please tell what for are you needing the rounding?

For conversion to human-readable decimal output, it's IMHO easier to first

convert to floating-point decimal and then round it.

Tauno Voipio

tauno voipio @ iki fi

Re: ROUND function source for IEEE-754

If you had had the courtesy to quote something to indicate to what

you were replying, you would have also seen the following:

together with a description of the round() function.

An elementary consideration of the operations required, and the

internal data formats, would show you that such short cuts are not

available. If ISO C adds the proposed decimal floating point

formats, that situation will change. Don't hold your breath for

it.

--

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

We've slightly trimmed the long signature. Click to see the full one.

Re: ROUND function source for IEEE-754

I'm glad for you. Of course we are all here purely to serve you.

Just let us know your demands in future, and watch the response.

--

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)

Available for consulting/temporary embedded and systems.

We've slightly trimmed the long signature. Click to see the full one.

#### Site Timeline

- » Powering a LPC2114 ARM7
- — Next thread in » Embedded Programming

- » ITU-R BT 656
- — Previous thread in » Embedded Programming

- » Webinar: Introducing the new Colibri SoM based on the NXP i.MX 6ULL SoC
- — Newest thread in » Embedded Programming

- » Wzmacniacz w.cz layout
- — The site's Newest Thread. Posted in » Electronics (Polish)

- » 1920 x 1080 o 3840 x 2160 ?
- — The site's Last Updated Thread. Posted in » Electronics Hobby (Italian)