# IEEE-754

Discussion in 'C Programming' started by =?ISO-8859-1?Q?Roman_T=F6ngi?=, Aug 23, 2007.

1. ### =?ISO-8859-1?Q?Roman_T=F6ngi?=Guest

IEEE-754 Arithmetic:
Most real numbers can't be stored exactly on the computer, but there can
be stated the range within which a machine number lies.

For the following example, I assume double precision and the round mode
in effect to be 'round to nearest' and that the number lies within the
normalized range:

Definitions:
x := real number
round(x) := correctly rounded normalized number
eps := machine epsilon (2^(-52) for double precision)
abs(x) := absolute value of x

That is:

round(x) = x*(1 + delta)

with delta:

abs(delta) <= 1/2*eps (round to nearest)

i.d. abs(delta) <= 2^(-53) (double precision)

abs(delta) corresponds to the relative rounding error.

Now I can state the range including round(x):

-----------------------------------------
x*(1-2(-53)) <= round(x) <= x*(1+2^(-53))
-----------------------------------------

Is this the correct range according to my assumptions?

Thanks a lot
Roman

=?ISO-8859-1?Q?Roman_T=F6ngi?=, Aug 23, 2007

2. ### Boudewijn DijkstraGuest

Op Thu, 23 Aug 2007 12:45:52 +0200 schreef Roman Töngi
<>:
> IEEE-754 Arithmetic:
> Most real numbers can't be stored exactly on the computer, but there can
> be stated the range within which a machine number lies.
>
> For the following example, I assume double precision and the round mode
> in effect to be 'round to nearest' and that the number lies within the
> normalized range:
>
> Definitions:
> x := real number
> round(x) := correctly rounded normalized number
> eps := machine epsilon (2^(-52) for double precision)
> abs(x) := absolute value of x
>
> That is:
> round(x) = x*(1 + delta)
>
> with delta:
> abs(delta) <= 1/2*eps (round to nearest)
> i.d. abs(delta) <= 2^(-53) (double precision)
>
> abs(delta) corresponds to the relative rounding error.
>
> Now I can state the range including round(x):
>
> -----------------------------------------
> x*(1-2(-53)) <= round(x) <= x*(1+2^(-53))
> -----------------------------------------
>
> Is this the correct range according to my assumptions?

Yes, but your assumptions are invalid. How did you arrive at a machine
epsilon of 2^(-52)?

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 23, 2007

3. ### Eric SosmanGuest

Roman Töngi wrote On 08/23/07 06:45,:
> IEEE-754 Arithmetic:
> Most real numbers can't be stored exactly on the computer, but there can
> be stated the range within which a machine number lies.
>
> For the following example, I assume double precision and the round mode
> in effect to be 'round to nearest' and that the number lies within the
> normalized range:
>
> Definitions:
> x := real number
> round(x) := correctly rounded normalized number
> eps := machine epsilon (2^(-52) for double precision)
> abs(x) := absolute value of x
>
> That is:
>
> round(x) = x*(1 + delta)
>
> with delta:
>
> abs(delta) <= 1/2*eps (round to nearest)
>
> i.d. abs(delta) <= 2^(-53) (double precision)
>
> abs(delta) corresponds to the relative rounding error.
>
> Now I can state the range including round(x):
>
> -----------------------------------------
> x*(1-2(-53)) <= round(x) <= x*(1+2^(-53))
> -----------------------------------------
>
> Is this the correct range according to my assumptions?

It looks right to me for x >= 0 (for x < 0 the
inequalities are backwards), and given suitable hand-
waving for abs(x) very small or very large. It might
be possible (I'm not sure) to sharpen the analysis a
tiny bit and change a `<=' to a `<', but whether that's
worth trying depends on your purpose in obtaining the
bound in the first place.

Note that the C language does not require IEEE
floating-point, nor does it require round-to-nearest,
nor does it specify the value of eps.

--

Eric Sosman, Aug 23, 2007
4. ### =?ISO-8859-15?Q?Roman_T=F6ngi?=Guest

Boudewijn Dijkstra wrote:
> Op Thu, 23 Aug 2007 12:45:52 +0200 schreef Roman Töngi
> <>:
>> IEEE-754 Arithmetic:
>> Most real numbers can't be stored exactly on the computer, but there can
>> be stated the range within which a machine number lies.
>>
>> For the following example, I assume double precision and the round
>> mode in effect to be 'round to nearest' and that the number lies
>> within the
>> normalized range:
>>
>> Definitions:
>> x := real number
>> round(x) := correctly rounded normalized number
>> eps := machine epsilon (2^(-52) for double precision)
>> abs(x) := absolute value of x
>>
>> That is:
>> round(x) = x*(1 + delta)
>>
>> with delta:
>> abs(delta) <= 1/2*eps (round to nearest)
>> i.d. abs(delta) <= 2^(-53) (double precision)
>>
>> abs(delta) corresponds to the relative rounding error.
>>
>> Now I can state the range including round(x):
>>
>> -----------------------------------------
>> x*(1-2(-53)) <= round(x) <= x*(1+2^(-53))
>> -----------------------------------------
>>
>> Is this the correct range according to my assumptions?

>
> Yes, but your assumptions are invalid. How did you arrive at a machine
> epsilon of 2^(-52)?
>
>

From the IEEE-specification for double format.

=?ISO-8859-15?Q?Roman_T=F6ngi?=, Aug 23, 2007
5. ### Boudewijn DijkstraGuest

Op Thu, 23 Aug 2007 18:08:15 +0200 schreef Roman Töngi
<>:
> Boudewijn Dijkstra wrote:
>> Op Thu, 23 Aug 2007 12:45:52 +0200 schreef Roman Töngi
>> <>:
>> How did you arrive at a machine epsilon of 2^(-52)?
>>

> From the IEEE-specification for double format.

I asked how, not where. Unless it says something like: "the machine
epsilon is 2^(-52); this corresponds to the upper limit of the rounding
error."

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 24, 2007
6. ### cr88192Guest

"Boudewijn Dijkstra" <> wrote in message
news...
> Op Thu, 23 Aug 2007 18:08:15 +0200 schreef Roman Töngi
> <>:
>> Boudewijn Dijkstra wrote:
>>> Op Thu, 23 Aug 2007 12:45:52 +0200 schreef Roman Töngi
>>> <>:
>>> How did you arrive at a machine epsilon of 2^(-52)?
>>>

>> From the IEEE-specification for double format.

>
> I asked how, not where. Unless it says something like: "the machine
> epsilon is 2^(-52); this corresponds to the upper limit of the rounding
> error."
>

my guess (probably OT here, oh well):

it will be this, presumably, unless the machine computes using less bits
than the format (such as if the calculations were internally performed with
floats, or with 48 bit mantissa values, or such).

may be a little higher really, as presumably the exact values of the low
order bits will depend on the exact HW.

for example, calculations performed with doubles in SSE are often slightly
off from those performed in the FPU, given the FPU uses an internal 80 bit
representation (with a 64 bit mantissa).

now, if our basic value is 1, and things are properly normalized (I think
this is required, except in the edge case of very small values), then our
epsilon is about the same as the relative weight of our low order bits.

now, if the major value were something other than 1, then the epsilon would
differ, in step with the exponent.

or such...

>
> --
> Gemaakt met Opera's revolutionaire e-mailprogramma:
> http://www.opera.com/mail/

cr88192, Aug 24, 2007
7. ### Boudewijn DijkstraGuest

Op Fri, 24 Aug 2007 12:17:09 +0200 schreef cr88192 <>:
> "Boudewijn Dijkstra" <> wrote in message
> news...
>> Op Thu, 23 Aug 2007 18:08:15 +0200 schreef Roman Töngi
>> <>:
>>> Boudewijn Dijkstra wrote:
>>>> Op Thu, 23 Aug 2007 12:45:52 +0200 schreef Roman Töngi
>>>> <>:
>>>> How did you arrive at a machine epsilon of 2^(-52)?
>>>>
>>> From the IEEE-specification for double format.

>>
>> I asked how, not where. Unless it says something like: "the machine
>> epsilon is 2^(-52); this corresponds to the upper limit of the rounding
>> error."
>>

> now, if our basic value is 1, and things are properly normalized (I think
> this is required, except in the edge case of very small values), then our
> epsilon is about the same as the relative weight of our low order bits.
>
>
> now, if the major value were something other than 1, then the epsilon
> would differ, in step with the exponent.
>
> or such...

Exactly. The epsilon will be proportional to the exponent.

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 27, 2007
8. ### Peter J. HolzerGuest

On 2007-08-27 07:24, Boudewijn Dijkstra <> wrote:
> Exactly. The epsilon will be proportional to the exponent.

And now read the OP again.

hp

--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"

Peter J. Holzer, Aug 27, 2007
9. ### Boudewijn DijkstraGuest

Op Mon, 27 Aug 2007 15:52:30 +0200 schreef Peter J. Holzer
<>:
> On 2007-08-27 07:24, Boudewijn Dijkstra <> wrote:
>> Exactly. The epsilon will be proportional to the exponent.

>
> And now read the OP again.

You're beyond me now. The OP was talking about a constant epsilon for the
whole range of numbers within the normalized range. Or did you read
something else between lines?

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 28, 2007
10. ### CBFalconerGuest

Boudewijn Dijkstra wrote:
> schreef Peter J. Holzer <>:
>> Boudewijn Dijkstra <> wrote:
>>
>>> Exactly. The epsilon will be proportional to the exponent.

>>
>> And now read the OP again.

>
> You're beyond me now. The OP was talking about a constant epsilon
> for the whole range of numbers within the normalized range. Or
> did you read something else between lines?

You are the first I have noted to consider 'proportional' to denote
a constant.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

CBFalconer, Aug 28, 2007
11. ### Peter J. HolzerGuest

On 2007-08-28 07:42, Boudewijn Dijkstra <> wrote:
> Op Mon, 27 Aug 2007 15:52:30 +0200 schreef Peter J. Holzer
><>:
>> On 2007-08-27 07:24, Boudewijn Dijkstra <> wrote:
>>> Exactly. The epsilon will be proportional to the exponent.

>>
>> And now read the OP again.

>
> You're beyond me now. The OP was talking about a constant epsilon for the
> whole range of numbers within the normalized range.

Yes, but that epsilon was always multiplied by the number:

| round(x) = x*(1 + delta)
^ here
|
| with delta:
|
| abs(delta) <= 1/2*eps (round to nearest)
|
| i.d. abs(delta) <= 2^(-53) (double precision)
|
| abs(delta) corresponds to the relative rounding error.
|
| Now I can state the range including round(x):
|
| -----------------------------------------
| x*(1-2(-53)) <= round(x) <= x*(1+2^(-53))
^ here ^ here
| -----------------------------------------

This is afaik the normal use of eps. See for example
http://en.wikipedia.org/wiki/Machine_epsilon.

> Or did you read something else between lines?

No, I just read the lines.

hp

--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"

Peter J. Holzer, Aug 28, 2007
12. ### Boudewijn DijkstraGuest

Op Tue, 28 Aug 2007 13:59:18 +0200 schreef CBFalconer
<>:
> Boudewijn Dijkstra wrote:
>> schreef Peter J. Holzer <>:
>>> Boudewijn Dijkstra <> wrote:
>>>
>>>> Exactly. The epsilon will be proportional to the exponent.
>>>
>>> And now read the OP again.

>>
>> You're beyond me now. The OP was talking about a constant epsilon
>> for the whole range of numbers within the normalized range. Or
>> did you read something else between lines?

>
> You are the first I have noted to consider 'proportional' to denote
> a constant.

You could note that, but it'd be more correct to note that I wasn't
denoting a constant, but an entity identified by the OP as a constant.

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 29, 2007
13. ### Boudewijn DijkstraGuest

Op Wed, 29 Aug 2007 00:45:30 +0200 schreef Peter J. Holzer
<>:
> On 2007-08-28 07:42, Boudewijn Dijkstra <> wrote:
>> Op Mon, 27 Aug 2007 15:52:30 +0200 schreef Peter J. Holzer
>> <>:
>>> On 2007-08-27 07:24, Boudewijn Dijkstra <> wrote:
>>>> Exactly. The epsilon will be proportional to the exponent.
>>>
>>> And now read the OP again.

>>
>> You're beyond me now. The OP was talking about a constant epsilon for
>> the whole range of numbers within the normalized range.

>
> Yes, but that epsilon was always multiplied by the number:
>
> | round(x) = x*(1 + delta)
> ^ here

Yes, you're right. I was being incredibly thick (which doesn't usually
happen (for this long)).

--
Gemaakt met Opera's revolutionaire e-mailprogramma:
http://www.opera.com/mail/

Boudewijn Dijkstra, Aug 29, 2007