The machine epsilon

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jacob navia

    #1

    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
    just answer in this thread.

    Thanks in advance for your help.
    ----------------------------------------------------------------------
    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
    // qfloat epsilon truncated so that it fits in this page...
    #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 float_radix=2.0 ;
    double inverse_radix = 1.0/float_radix;
    double machine_precisi on = 1.0;
    double temp = 1.0 + machine_precisi on;

    while (temp != 1.0) {
    machine_precisi on *= inverse_radix;
    temp = 1.0 + machine_precisi on ;
    printf("%.17g\n ",machine_preci sion);
    }
    return 0;
    }
  • Richard Heathfield

    #2
    Re: The machine epsilon

    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
    // qfloat epsilon truncated so that it fits in this page...
    #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.

    Your text suffers from your usual confusion between lcc-win32 and C.

    <snip>

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • jacob navia

      #3
      Re: The machine epsilon

      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
      >// qfloat epsilon truncated so that it fits in this page...
      >#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.

      Comment

      • Richard Tobin

        #4
        Re: The machine epsilon

        In article <4684cc3c$0$273 66$ba4acef3@new s.orange.fr>,
        jacob navia <jacob@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.

        Comment

        • jacob navia

          #5
          Re: The machine epsilon

          Richard Tobin wrote:
          In article <4684cc3c$0$273 66$ba4acef3@new s.orange.fr>,
          jacob navia <jacob@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.

          Comment

          • Richard Heathfield

            #6
            Re: The machine epsilon

            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
            >>// qfloat epsilon truncated so that it fits in this page...
            >>#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@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • Richard Heathfield

              #7
              Re: The machine epsilon

              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@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • Richard Tobin

                #8
                Re: The machine epsilon

                In article <Teidna5iB9yQTh nbnZ2dnUVZ8sTin Z2d@bt.com>,
                Richard Heathfield <rjh@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.

                Comment

                • Richard Heathfield

                  #9
                  Re: The machine epsilon

                  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@
                  Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                  "Usenet is a strange place" - dmr 29 July 1999

                  Comment

                  • Richard Tobin

                    #10
                    Re: The machine epsilon

                    In article <V6mdnVPRuLoCcB nbnZ2dnUVZ_oWdn Z2d@comcast.com >,
                    Eric Sosman <esosman@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.

                    Comment

                    • Eric Sosman

                      #11
                      Re: The machine epsilon

                      Richard Tobin wrote:
                      In article <V6mdnVPRuLoCcB nbnZ2dnUVZ_oWdn Z2d@comcast.com >,
                      Eric Sosman <esosman@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).
                      Right: Not equal to the bias, as I said. (And in any case
                      it's wrong to speak of the exponent *value* being equal to the
                      bias or to the bias minus delta: the exponent is 1-delta and
                      the bias crops up in the *encoding* of that value.)

                      --
                      Eric Sosman
                      esosman@acm-dot-org.invalid

                      Comment

                      • Richard Tobin

                        #12
                        Re: The machine epsilon

                        In article <p8ydnd7w3dsxYR nbnZ2dnUVZ_hGdn Z2d@comcast.com >,
                        Eric Sosman <esosman@acm-dot-org.invalidwrot e:
                        >(And in any case
                        >it's wrong to speak of the exponent *value* being equal to the
                        >bias or to the bias minus delta: the exponent is 1-delta and
                        >the bias crops up in the *encoding* of that value.)
                        Surely you mean 0-delta?

                        It does seem to be common to call the encoded value the exponent; I
                        suppose the context usually makes it clear. But I agree that it's
                        inaccurate - I should have said the "exponent bits" or the "encoded
                        exponent" or something like that.

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

                        Comment

                        • Army1987

                          #13
                          Re: The machine epsilon


                          "jacob navia" <jacob@jacob.re mcomp.frha scritto nel messaggio news:4684cc3c$0 $27366$ba4acef3 @news.orange.fr ...
                          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
                          >>// qfloat epsilon truncated so that it fits in this page...
                          >>#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.
                          Where does it allow you to use an identifier which doesn't begin
                          with an underscore and the standard never reserves?
                          What happens if i write a program with the lines
                          #include <float.h>
                          int main(int QFLT_EPSILON, char *argv[])
                          (yes, I'm allowed to do that) and try to compile it with your
                          compiler?


                          Comment

                          • jacob navia

                            #14
                            Re: The machine epsilon

                            Richard Tobin wrote:
                            In article <V6mdnVPRuLoCcB nbnZ2dnUVZ_oWdn Z2d@comcast.com >,
                            Eric Sosman <esosman@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
                            That is what I am trying to say. The epsilon is
                            sign: 0
                            exponent: zero, i.e. the bias.
                            mantissa: 0000000000 0000000000 0000000000 0000000000 0000000000 01
                            <--10-->
                            Using printf:
                            printf("%a",DBL _EPSILON); 0x1.00000000000 00p-052

                            Comment

                            • jacob navia

                              #15
                              Re: The machine epsilon

                              jacob navia wrote:
                              mantissa: 0000000000 0000000000 0000000000 0000000000 0000000000 01
                              This is wrong, excuse me. The mantissa is normalized, and the bits are:
                              100000000 etc

                              The value is 2^-52--2.2204460492503 130808472633361 816e-16

                              Comment

                              Working...