Most negative double value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Ammon

    Most negative double value

    What's the most negative double value I can get? Is it always
    guaranteed to be -DBL_MAX? If so, why (or rather, where)?

    Thanks.

  • Malcolm

    #2
    Re: Most negative double value


    "Peter Ammon" <peter_ammon@ro cketmail.com> wrote in message[color=blue]
    > What's the most negative double value I can get? Is it always
    > guaranteed to be -DBL_MAX? If so, why (or rather, where)?
    >[/color]
    Most floating point formats have a negative flag bit which can be set or
    unset. The most natural system is for the maximum and minimum to be of the
    same magnitude.



    Comment

    • Papadopoulos Giannis

      #3
      Re: Most negative double value

      Peter Ammon wrote:[color=blue]
      > What's the most negative double value I can get? Is it always
      > guaranteed to be -DBL_MAX? If so, why (or rather, where)?
      >
      > Thanks.
      >[/color]

      It is DBL_MIN and it is always -DBL_MAX in IEEE-754 compliant systems..

      --
      #include <stdio.h>
      #define p(s) printf(#s" endian")
      int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}

      Giannis Papadopoulos

      University of Thessaly
      Computer & Communications Engineering dept.

      Comment

      • Peter Ammon

        #4
        Re: Most negative double value

        Papadopoulos Giannis wrote:[color=blue]
        > Peter Ammon wrote:
        >[color=green]
        >> What's the most negative double value I can get? Is it always
        >> guaranteed to be -DBL_MAX? If so, why (or rather, where)?
        >>
        >> Thanks.
        >>[/color]
        >
        > It is DBL_MIN and it is always -DBL_MAX in IEEE-754 compliant systems..[/color]

        DBL_MIN on my platform is 2.2250738585072 014e-308 which is positive.

        --
        Pull out a splinter to reply.

        Comment

        • Papadopoulos Giannis

          #5
          Re: Most negative double value

          Peter Ammon wrote:[color=blue]
          > Papadopoulos Giannis wrote:
          >[color=green]
          >> Peter Ammon wrote:
          >>[color=darkred]
          >>> What's the most negative double value I can get? Is it always
          >>> guaranteed to be -DBL_MAX? If so, why (or rather, where)?
          >>>
          >>> Thanks.
          >>>[/color]
          >>
          >> It is DBL_MIN and it is always -DBL_MAX in IEEE-754 compliant systems..[/color]
          >
          >
          > DBL_MIN on my platform is 2.2250738585072 014e-308 which is positive.
          >[/color]
          F**K.....
          I should never post again after 02:00 in the morning...

          Yes, the most negative value is -DBL_MAX...
          The smallest positive is DBL_MIN...

          A big sorry...

          --
          #include <stdio.h>
          #define p(s) printf(#s" endian")
          int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}

          Giannis Papadopoulos

          University of Thessaly
          Computer & Communications Engineering dept.

          Comment

          • Christian Bau

            #6
            Re: Most negative double value

            In article <c13jg2$hit$1@u lysses.noc.ntua .gr>,
            Papadopoulos Giannis <ipapadop@inf.u th.gr> wrote:
            [color=blue]
            > #include <stdio.h>
            > #define p(s) printf(#s" endian")
            > int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}[/color]

            You are aware that this is nonsense?

            If not, then think about it for five minutes before you respond.

            Comment

            • CBFalconer

              #7
              Re: Most negative double value

              Peter Ammon wrote:[color=blue]
              > Papadopoulos Giannis wrote:[color=green]
              > > Peter Ammon wrote:
              > >[color=darkred]
              > >> What's the most negative double value I can get? Is it always
              > >> guaranteed to be -DBL_MAX? If so, why (or rather, where)?[/color]
              > >
              > > It is DBL_MIN and it is always -DBL_MAX in IEEE-754 compliant systems..[/color]
              >
              > DBL_MIN on my platform is 2.2250738585072 014e-308 which is positive.[/color]

              Which is apparently correct. From N869:

              [#10] The values given in the following list shall be
              replaced by implementation-defined constant expressions with
              (positive) values that are less than or equal to those
              shown:

              -- the difference between 1 and the least value greater
              than 1 that is representable in the given floating
              point type, b1-p

              FLT_EPSILON 1E-5
              DBL_EPSILON 1E-9
              LDBL_EPSILON 1E-9

              -- minimum normalized positive floating-point number,
              bemin-1

              FLT_MIN 1E-37
              DBL_MIN 1E-37
              LDBL_MIN 1E-37

              --
              Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
              Available for consulting/temporary embedded and systems.
              <http://cbfalconer.home .att.net> USE worldnet address!

              Comment

              • Dan Pop

                #8
                Re: Most negative double value

                In <c132k7$gvp$1@n ews.apple.com> Peter Ammon <peter_ammon@ro cketmail.com> writes:
                [color=blue]
                >What's the most negative double value I can get? Is it always
                >guaranteed to be -DBL_MAX?[/color]

                Yes.
                [color=blue]
                >If so, why (or rather, where)?[/color]

                Because the standard uses a sign-magnitude model for the floating point
                numbers. 5.2.4.2.2 in C99. Sorry, but the text is next to impossible
                to quote in plain text format, without using some special convention,
                a la TeX and friends.

                Dan
                --
                Dan Pop
                DESY Zeuthen, RZ group
                Email: Dan.Pop@ifh.de

                Comment

                • Papadopoulos Giannis

                  #9
                  Re: Most negative double value

                  Christian Bau wrote:[color=blue]
                  > In article <c13jg2$hit$1@u lysses.noc.ntua .gr>,
                  > Papadopoulos Giannis <ipapadop@inf.u th.gr> wrote:
                  >
                  >[color=green]
                  >>#include <stdio.h>
                  >>#define p(s) printf(#s" endian")
                  >>int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}[/color]
                  >
                  >
                  > You are aware that this is nonsense?
                  >
                  > If not, then think about it for five minutes before you respond.[/color]

                  Please explain...

                  --
                  #include <stdio.h>
                  #define p(s) printf(#s" endian")
                  int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}

                  Giannis Papadopoulos

                  University of Thessaly
                  Computer & Communications Engineering dept.

                  Comment

                  • Christian Bau

                    #10
                    Re: Most negative double value

                    In article <c15dn0$r78$1@u lysses.noc.ntua .gr>,
                    Papadopoulos Giannis <ipapadop@inf.u th.gr> wrote:
                    [color=blue]
                    > Christian Bau wrote:[color=green]
                    > > In article <c13jg2$hit$1@u lysses.noc.ntua .gr>,
                    > > Papadopoulos Giannis <ipapadop@inf.u th.gr> wrote:
                    > >
                    > >[color=darkred]
                    > >>#include <stdio.h>
                    > >>#define p(s) printf(#s" endian")
                    > >>int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}[/color]
                    > >
                    > >
                    > > You are aware that this is nonsense?
                    > >
                    > > If not, then think about it for five minutes before you respond.[/color]
                    >
                    > Please explain...[/color]

                    Do you think that bigendian and littleendian are the only possibilities?
                    Could the char that you are reading consist completely of padding bits
                    in the int, in which case you could get two different results when you
                    run the program twice?

                    Comment

                    • Old Wolf

                      #11
                      Re: Most negative double value

                      > > >>#include <stdio.h>[color=blue][color=green][color=darkred]
                      > > >>#define p(s) printf(#s" endian")
                      > > >>int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}
                      > > >
                      > > >
                      > > > You are aware that this is nonsense?
                      > > >
                      > > > If not, then think about it for five minutes before you respond.[/color]
                      > >
                      > > Please explain...[/color]
                      >
                      > Do you think that bigendian and littleendian are the only possibilities?
                      > Could the char that you are reading consist completely of padding bits
                      > in the int, in which case you could get two different results when you
                      > run the program twice?[/color]

                      Do you think that "endianness-detector" is the only possibility
                      for the purpose of this program? It could in fact be a random
                      greeting program in Martian, or a pedant-trapper, or a
                      compiler test, or pretty much anything really.

                      Comment

                      • Papadopoulos Giannis

                        #12
                        Re: Most negative double value

                        Christian Bau wrote:[color=blue]
                        > Do you think that bigendian and littleendian are the only possibilities?[/color]

                        No, but I believe that are the most common ones..
                        [color=blue]
                        > Could the char that you are reading consist completely of padding bits
                        > in the int, in which case you could get two different results when you
                        > run the program twice?[/color]

                        I think if I change *(char*)&v to *(char*)&v==1 I can rid of it.. Or
                        don't I??

                        PS If the code below does not work (and I have come across it many
                        times, in books and the Inet), then what should??

                        --
                        #include <stdio.h>
                        #define p(s) printf(#s" endian")
                        int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}

                        Giannis Papadopoulos

                        University of Thessaly
                        Computer & Communications Engineering dept.

                        Comment

                        • Peter Ammon

                          #13
                          Re: Most negative double value

                          Dan Pop wrote:
                          [color=blue]
                          > In <c132k7$gvp$1@n ews.apple.com> Peter Ammon <peter_ammon@ro cketmail.com> writes:
                          >
                          >[color=green]
                          >>What's the most negative double value I can get? Is it always
                          >>guaranteed to be -DBL_MAX?[/color]
                          >
                          >
                          > Yes.
                          >
                          >[color=green]
                          >>If so, why (or rather, where)?[/color]
                          >
                          >
                          > Because the standard uses a sign-magnitude model for the floating point
                          > numbers. 5.2.4.2.2 in C99. Sorry, but the text is next to impossible
                          > to quote in plain text format, without using some special convention,
                          > a la TeX and friends.
                          >
                          > Dan[/color]

                          There it is! Thanks.

                          -Peter

                          --
                          Pull out a splinter to reply.

                          Comment

                          • Christian Bau

                            #14
                            Re: Most negative double value

                            In article <c17q21$1rv7$1@ ulysses.noc.ntu a.gr>,
                            Papadopoulos Giannis <ipapadop@inf.u th.gr> wrote:
                            [color=blue]
                            > Christian Bau wrote:[color=green]
                            > > Do you think that bigendian and littleendian are the only possibilities?[/color]
                            >
                            > No, but I believe that are the most common ones..
                            >[color=green]
                            > > Could the char that you are reading consist completely of padding bits
                            > > in the int, in which case you could get two different results when you
                            > > run the program twice?[/color]
                            >
                            > I think if I change *(char*)&v to *(char*)&v==1 I can rid of it.. Or
                            > don't I??
                            >
                            > PS If the code below does not work (and I have come across it many
                            > times, in books and the Inet), then what should??[/color]

                            The pragmatic solution is to add an appropriate #define into some header
                            file. Also helpful is to write code that doesn't depend on endianness in
                            the first place: For example, to write a value x up to 2^32 to a file,
                            write the bytes (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x &
                            0xff and you will get the same results everywhere.

                            C doesn't even say that there is such a thing as a "byte ordering": If
                            for example int has 16 bit, char has 8 bit, and sizeof (int) == 2, then
                            the 16 bits of an int could be mapped in any possible permutation to the
                            16 bits in an array of two chars.

                            Comment

                            • Christian Bau

                              #15
                              Re: Most negative double value

                              In article <843a4f78.04022 10449.204e81aa@ posting.google. com>,
                              oldwolf@inspire .net.nz (Old Wolf) wrote:
                              [color=blue][color=green][color=darkred]
                              > > > >>#include <stdio.h>
                              > > > >>#define p(s) printf(#s" endian")
                              > > > >>int main(void){int v=1;*(char*)&v? p(Little):p(Big );return 0;}
                              > > > >
                              > > > >
                              > > > > You are aware that this is nonsense?
                              > > > >
                              > > > > If not, then think about it for five minutes before you respond.
                              > > >
                              > > > Please explain...[/color]
                              > >
                              > > Do you think that bigendian and littleendian are the only possibilities?
                              > > Could the char that you are reading consist completely of padding bits
                              > > in the int, in which case you could get two different results when you
                              > > run the program twice?[/color]
                              >
                              > Do you think that "endianness-detector" is the only possibility
                              > for the purpose of this program? It could in fact be a random
                              > greeting program in Martian, or a pedant-trapper, or a
                              > compiler test, or pretty much anything really.[/color]

                              If you read the next reply of the original poster, you will find that it
                              is an "endianness-detector".

                              Comment

                              Working...