473,699 Members | 2,531 Online

# The machine epsilon

Hi.

Continuing with my tutorial, here is an entry I have added recently. I
hope it is not controversial. If you see any errors/ambiguities/etc please

----------------------------------------------------------------------
The machine epsilon

The machine epsilon is the smallest number that changes the result of an
addition operation at the point where the representation of the numbers
is the densest. In IEEE754 representation this number has an exponent
value of the bias, and a fraction of 1. If you add a number smaller than
this to 1.0, the result will be 1.0. For the different representations
we have in the standard header <float.h>:

#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106

This defines are part of the C99 ANSI standard. For the standard types
(float, double and long double) this defines should always exist in
other compilers.

Here is a program that will find out the machine epsilon for a given
floating point representation.

#include <stdio.h>
int main(void)
{
double machine_precisi on = 1.0;
double temp = 1.0 + machine_precisi on;

while (temp != 1.0) {
temp = 1.0 + machine_precisi on ;
printf("%.17g\n ",machine_preci sion);
}
return 0;
}
Jun 29 '07 #1
39 17812
jacob navia said:

<snip>
For the different
representations we have in the standard header <float.h>:

#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106
Conforming implementations must not define QFLT_EPSILON in <float.h>
This defines are part of the C99 ANSI standard.
Well, three of them are.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Jun 29 '07 #2
Richard Heathfield wrote:
jacob navia said:

<snip>
>For the different
representation s we have in the standard header <float.h>:

#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106

Conforming implementations must not define QFLT_EPSILON in <float.h>
The C standard paragraph J.5.6: Common extensions:
J.5.6 Other arithmetic types
Additional arithmetic types, such as _ _int128 or double double, and
their appropriate conversions are defined (6.2.5, 6.3.1). Additional
floating types may have more range or precision than long double, may be
used for evaluating expressions of other floating types, and may be
used to define float_t or double_t.
>
>This defines are part of the C99 ANSI standard.

Well, three of them are.
You cut the next sentence!

"For the standard types (float, double and long double) this defines
should always exist in other compilers. "

This is a good example of BIAS when quoting.
Jun 29 '07 #3
In article <46************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:
>>This defines are part of the C99 ANSI standard.
Presumably you meant "these", not "this". And it would be less jargonish
to say "definition s" rather than "defines".
>Well, three of them are.

You cut the next sentence!

"For the standard types (float, double and long double) this defines
should always exist in other compilers. "

This is a good example of BIAS when quoting.
I don't think so. There's no need to say something that's wrong here,
even if you clarify it in the next sentence.

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 29 '07 #4
Richard Tobin wrote:
In article <46************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:
>>>This defines are part of the C99 ANSI standard.

Presumably you meant "these", not "this". And it would be less jargonish
to say "definition s" rather than "defines".
>>Well, three of them are.
You cut the next sentence!

"For the standard types (float, double and long double) this defines
should always exist in other compilers. "

This is a good example of BIAS when quoting.

I don't think so. There's no need to say something that's wrong here,
even if you clarify it in the next sentence.

-- Richard
OK. Now it is:

These definitions (except the qfloat part) are part of the C99 ANSI
standard. For the standard types (float, double and long double) they
should always exist in other compilers. The type qfloat is an extension
of lcc-win32.

Jun 29 '07 #5
jacob navia said:
Richard Heathfield wrote:
>jacob navia said:

<snip>
>>For the different
representatio ns we have in the standard header <float.h>:

#define FLT_EPSILON 1.19209290e-07F // float
#define DBL_EPSILON 2.2204460492503 131e-16 // double
#define LDBL_EPSILON 1.0842021724855 04434007452e-19L //long double
#define QFLT_EPSILON 1.0900377190486 584296973751359 3110651 ... E-106

Conforming implementations must not define QFLT_EPSILON in <float.h>

The C standard paragraph J.5.6: Common extensions:
J.5.6 Other arithmetic types
Additional arithmetic types, such as _ _int128 or double double, and
their appropriate conversions are defined (6.2.5, 6.3.1). Additional
floating types may have more range or precision than long double, may
be
used for evaluating expressions of other floating types, and may be
used to define float_t or double_t.
What has that to do with what I said? I didn't say that implementations
can't provide extra types. I said a conforming implementation must not
define QFLT_EPSILON in <float.h- that is not the same as saying that
implementations cannot provide extra types.
>>This defines are part of the C99 ANSI standard.

Well, three of them are.

You cut the next sentence!
Yes. It was not relevant to my point, which is that QFLT_EPSILON is not
part of the C Standard.

"For the standard types (float, double and long double) this defines
should always exist in other compilers. "

This is a good example of BIAS when quoting.
No, it isn't. Your statement incorrectly claimed that QFLT_EPSILON was
part of the C99 Standard. The fact that it was followed by another
statement which didn't reiterate the claim does not make your original
claim correct.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Jun 29 '07 #6
jacob navia said:

<snip>
OK. Now it is:

These definitions (except the qfloat part) are part of the C99 ANSI
standard. For the standard types (float, double and long double) they
should always exist in other compilers. The type qfloat is an
extension of lcc-win32.
Why mention lcc-win32 extensions in a C tutorial?

And if it's an lcc-win32 tutorial, why ask for comment in a C newsgroup?
Is there not an lcc-win32 newsgroup where you can discuss lcc-win32
extensions?

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Jun 29 '07 #7
In article <Te************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>Why mention lcc-win32 extensions in a C tutorial?

And if it's an lcc-win32 tutorial, why ask for comment in a C newsgroup?
Is there not an lcc-win32 newsgroup where you can discuss lcc-win32
extensions?
You're not being reasonable. He's writing a C tutorial intended for
lcc-win32 users. Since most of it is standard C, I see no reason why
he shouldn't post about it here.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 29 '07 #8
Richard Tobin said:

<snip>
You're not being reasonable.
Shurely shome mishtake?
He's writing a C tutorial
The internal evidence of his articles suggests otherwise.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Jun 29 '07 #9
In article <V6************ *************** ***@comcast.com >,
Eric Sosman <es*****@acm-dot-org.invalidwrot e:

>In IEEE754 representation this number has an exponent
value of the bias, and a fraction of 1.
If by "the bias" you mean the traditional offset in the
encoding of the exponent, then I think this statement is wrong.
An FP epsilon has to do with the precision of the fraction,
not with the span of possible exponents.
The epsilon is such that if it were de-normalised to have the same
exponent as 1.0, only the lowest bit of the fraction would be set. To
normalise it, you need to shift that lowest bit up into the hidden
bit, and adjust the exponent accordingly. For 1.0, the exponent is
equal to the bias. So the epsilon has an exponent equal to the bias
minus the number of fraction bits, and the fraction part is zero
(because of the hidden bit).

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 29 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.