memset all bits to zero will let float/double to zero?

Discussion in 'C Programming' started by Zhiqiang Ye, Jun 16, 2004.

  1. Zhiqiang Ye

    Zhiqiang Ye Guest

    Hi, All
    I am reading FAQ of this group. I have a question about this:
    http://www.eskimo.com/~scs/C-faq/q7.31.html

    It says:
    "
    p = malloc(m * n);
    memset(p, 0, m * n);
    The zero fill is all-bits-zero, and does not therefore guarantee useful null
    pointer values (see section 5 of this list) or floating-point zero values.
    "

    but ieee754 defined float zero to be all-bits-zero.

    Anyone can help to explain about this?

    Thanks in advance.
     
    Zhiqiang Ye, Jun 16, 2004
    #1
    1. Advertising

  2. Zhiqiang Ye

    Grumble Guest

    Zhiqiang Ye wrote:

    > I am reading FAQ of this group. I have a question about this:
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    > "
    > p = malloc(m * n);
    > memset(p, 0, m * n);
    > The zero fill is all-bits-zero, and does not therefore guarantee useful null
    > pointer values (see section 5 of this list) or floating-point zero values.
    > "
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?


    Here's a wild guess.

    Because IEEE 754 support is not mandatory? Thus you cannot, portably,
    assume that every compiler will implement the formats specified by the
    IEEE 754 standard.
     
    Grumble, Jun 16, 2004
    #2
    1. Advertising

  3. Zhiqiang Ye

    Dan Pop Guest

    In <cap8jq$2kb1$99.com> "Zhiqiang Ye" <> writes:

    > I am reading FAQ of this group. I have a question about this:
    >http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    >It says:
    >"
    >p = malloc(m * n);
    >memset(p, 0, m * n);
    >The zero fill is all-bits-zero, and does not therefore guarantee useful null
    >pointer values (see section 5 of this list) or floating-point zero values.
    >"
    >
    >but ieee754 defined float zero to be all-bits-zero.
    >
    >Anyone can help to explain about this?


    The C standard doesn't say that floating point types *must* follow the
    IEEE-754 specification. There are other floating point representations
    where all bits zero doesn't mean zero.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jun 16, 2004
    #3
  4. In article <cap8jq$2kb1$99.com>,
    Zhiqiang Ye <> wrote:

    >The zero fill is all-bits-zero, and does not therefore guarantee useful null
    >pointer values (see section 5 of this list) or floating-point zero values.


    >but ieee754 defined float zero to be all-bits-zero.


    So *if* your C omplementation uses IEEE floating point, the values will
    be zero.

    -- Richard
     
    Richard Tobin, Jun 16, 2004
    #4
  5. Zhiqiang Ye

    Chris Dollin Guest

    Zhiqiang Ye wrote:

    > Hi, All
    > I am reading FAQ of this group. I have a question about this:
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    > "
    > p = malloc(m * n);
    > memset(p, 0, m * n);
    > The zero fill is all-bits-zero, and does not therefore guarantee useful
    > null pointer values (see section 5 of this list) or floating-point zero
    > values. "
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?


    C doesn't require implementations to use IEEE754, if I recall correctly.

    --
    Chris "electric hedgehog" Dollin
    C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
    C welcome: http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
     
    Chris Dollin, Jun 16, 2004
    #5
  6. Zhiqiang Ye

    Dan Pop Guest

    In <cap9fg$8sj$> Grumble <> writes:

    >Zhiqiang Ye wrote:
    >
    >> I am reading FAQ of this group. I have a question about this:
    >> http://www.eskimo.com/~scs/C-faq/q7.31.html
    >>
    >> It says:
    >> "
    >> p = malloc(m * n);
    >> memset(p, 0, m * n);
    >> The zero fill is all-bits-zero, and does not therefore guarantee useful null
    >> pointer values (see section 5 of this list) or floating-point zero values.
    >> "
    >>
    >> but ieee754 defined float zero to be all-bits-zero.
    >>
    >> Anyone can help to explain about this?

    >
    >Here's a wild guess.
    >
    >Because IEEE 754 support is not mandatory? Thus you cannot, portably,
    >assume that every compiler will implement the formats specified by the
    >IEEE 754 standard.


    IEEE 754 is particularly expensive when done in software, because the
    underlying hardware provides no floating point support. Therefore,
    implementations for such hardware either use a different floating point
    format or provide two floating point representations: IEEE 754 and
    something faster.

    For example, MS C implementations for the 80[23]86 came with both
    80[23]87 emulation (i.e. IEEE 754 implemented in software) and with an
    implementation of a Microsoft-designed floating point format. The former
    could transparently exploit an 80[23]87 chip, if present, the latter was
    significantly faster on systems without an 80[23]87 chip, but couldn't
    benefit from such a chip, if present.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jun 16, 2004
    #6
  7. Zhiqiang Ye <> wrote:
    > Hi, All
    > I am reading FAQ of this group. I have a question about this:
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    > "
    > p = malloc(m * n);
    > memset(p, 0, m * n);
    > The zero fill is all-bits-zero, and does not therefore guarantee useful null
    > pointer values (see section 5 of this list) or floating-point zero values.
    > "
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?


    Very simple. There are other floating-point formats than those defined
    in IEEE754. The C standard does not guarantee or require that IEEE754
    is used.


    --
    <Insert your favourite quote here.>
    Erik Trulsson
     
    Erik Trulsson, Jun 16, 2004
    #7
  8. Zhiqiang Ye wrote:
    > I am reading FAQ of this group. I have a question about this:
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    > "
    > p = malloc(m * n);
    > memset(p, 0, m * n);
    > The zero fill is all-bits-zero, and does not therefore guarantee useful null
    > pointer values (see section 5 of this list) or floating-point zero values.
    > "
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?
    >


    IEEE 754 specification is not a part of C language specification.
    Implementations are not required to conform to IEEE 754.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Jun 16, 2004
    #8
  9. >p = malloc(m * n);
    >memset(p, 0, m * n);
    >The zero fill is all-bits-zero, and does not therefore guarantee useful null
    >pointer values (see section 5 of this list) or floating-point zero values.
    >"
    >
    >but ieee754 defined float zero to be all-bits-zero.


    ieee754 defined two DIFFERENT floating point representations for zero,
    and they can't both be all-bits-zero. Also, not everyone uses ieee754
    floating point.

    Gordon L. Burditt
     
    Gordon Burditt, Jun 16, 2004
    #9
  10. In article <cap8jq$2kb1$99.com>,
    "Zhiqiang Ye" <> wrote:

    > Hi, All
    > I am reading FAQ of this group. I have a question about this:
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    > "
    > p = malloc(m * n);
    > memset(p, 0, m * n);
    > The zero fill is all-bits-zero, and does not therefore guarantee useful null
    > pointer values (see section 5 of this list) or floating-point zero values.
    > "
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?


    But C doesn't guarantee ieee754.
     
    Christian Bau, Jun 16, 2004
    #10
  11. Zhiqiang Ye wrote:

    > I am reading FAQ of this group. I have a question about this:
    >
    > http://www.eskimo.com/~scs/C-faq/q7.31.html
    >
    > It says:
    >
    > p = malloc(m*n);
    > memset(p, 0, m*n);
    >
    > The zero fill is all-bits-zero and does not, therefore,
    > guarantee useful null pointer values (see section 5 of this list)
    > or floating-point zero values.
    >
    > but ieee754 defined float zero to be all-bits-zero.
    >
    > Anyone can help to explain about this?


    I don't think that you need to worry about this.
    Every floating-point implementation on every machine
    to which you are likely to port your software
    recognizes "all-zero-bits"
    to be a representation of floating-point +0.0

    Unlike Java, the C language standard does need to specify
    the representation of null pointers of floating-point numbers
    so it doesn't.
    This leaves open the possibility that implementations (compilers)
    may use some other representation.
    But, there are no implementations of the C 89 or C99 standard
    that use anything but all zero bits to represent NULL or +0.0.
     
    E. Robert Tisdale, Jun 16, 2004
    #11
  12. (Gordon Burditt) writes:
    > >p = malloc(m * n);
    > >memset(p, 0, m * n);
    > >The zero fill is all-bits-zero, and does not therefore guarantee useful null
    > >pointer values (see section 5 of this list) or floating-point zero values.
    > >"
    > >
    > >but ieee754 defined float zero to be all-bits-zero.

    >
    > ieee754 defined two DIFFERENT floating point representations for zero,
    > and they can't both be all-bits-zero. Also, not everyone uses ieee754
    > floating point.


    IEEE754 0.0 is not necessarily all-bits-zero, but all-bits-zero is
    necessarily IEEE754 0.0.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jun 17, 2004
    #12
  13. (Dan Pop) writes:
    [...]
    > The C standard doesn't say that floating point types *must* follow the
    > IEEE-754 specification. There are other floating point representations
    > where all bits zero doesn't mean zero.


    Are any such representations currently being used?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jun 17, 2004
    #13
  14. Zhiqiang Ye

    CBFalconer Guest

    "E. Robert Tisdale" wrote:
    >

    .... snip ...
    >
    > But, there are no implementations of the C 89 or C99 standard
    > that use anything but all zero bits to represent NULL or +0.0.


    Obviously you have secured and exhaustively examined every std C
    implementation on any machine whatsoever. Sounds like a lot of
    work. Was this funded by NASA, and how did you determine that you
    checked each and every one? Where did you put those myriad
    systems?

    Maybe we should all write NASA and ask for the report. The
    exhaustive listing should be useful. Being government funded it
    should be freely available.

    While doing all this, how did you find time for trolling and
    spewing misinformation?

    --
    fix (vb.): 1. to paper over, obscure, hide from public view; 2.
    to work around, in a way that produces unintended consequences
    that are worse than the original problem. Usage: "Windows ME
    fixes many of the shortcomings of Windows 98 SE". - Hutchison
     
    CBFalconer, Jun 17, 2004
    #14
  15. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Keith Thompson wrote:
    | (Dan Pop) writes:
    | [...]
    |
    |>The C standard doesn't say that floating point types *must* follow the
    |>IEEE-754 specification. There are other floating point representations
    |>where all bits zero doesn't mean zero.
    |
    |
    | Are any such representations currently being used?
    |

    IIRC, my TI-83 calculator uses a packed BCD representation for the
    mantissa and an 8-bit 2's compliment number for the (decimal) exponent.
    I would imagine BCD is quite common in calculators. However, you get
    lucky again as all bits zero still means zero and, FWIW, I don't believe
    there is an ISO C compiler for it.

    Ross


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)
    Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

    iD8DBQFA0W/P9bR4xmappRARAvd8AJwNpS+6UpF2SFil/Dasb2/zJGolSACgtRyn
    BwPyCXIFzRQQF6+mpAiXQxk=
    =Z19n
    -----END PGP SIGNATURE-----
     
    Ross Kendall Axe, Jun 17, 2004
    #15
  16. Zhiqiang Ye

    Anarchist Guest

    > Are any such representations currently being used?

    <laugh> No, none at all. It is just fun for the regulars to insist on
    possibility even when all computers out there are using IEEE-754 or
    IEEE-854.

    Anarchist
     
    Anarchist, Jun 17, 2004
    #16
  17. Zhiqiang Ye

    Dan Pop Guest

    In <caq9oj$> (Gordon Burditt) writes:

    >>p = malloc(m * n);
    >>memset(p, 0, m * n);
    >>The zero fill is all-bits-zero, and does not therefore guarantee useful null
    >>pointer values (see section 5 of this list) or floating-point zero values.
    >>"
    >>
    >>but ieee754 defined float zero to be all-bits-zero.

    >
    >ieee754 defined two DIFFERENT floating point representations for zero,
    >and they can't both be all-bits-zero.


    This is irrelevant, if ieee754 implementations must support both of them
    at the same time.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jun 17, 2004
    #17
  18. Zhiqiang Ye

    Dan Pop Guest

    In <> Keith Thompson <> writes:

    > (Dan Pop) writes:
    >[...]
    >> The C standard doesn't say that floating point types *must* follow the
    >> IEEE-754 specification. There are other floating point representations
    >> where all bits zero doesn't mean zero.

    >
    >Are any such representations currently being used?


    Not that I know of. Those representations were usually used by software
    implementations of floating point, which are today quasi-extinct (at
    least on hosted implementations).

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jun 17, 2004
    #18
  19. "Anarchist" <> writes:
    > > Are any such representations currently being used?

    >
    > <laugh> No, none at all. It is just fun for the regulars to insist on
    > possibility even when all computers out there are using IEEE-754 or
    > IEEE-854.


    The question was whether there are floating-point representations
    being used in which all-bit-zero does not represent 0.0. So far,
    nobody has cited one.

    But it's certainly not the case that all computers out there are using
    IEEE-754 or IEE-854. Non-IEEE representations are becoming less
    common, but there's not extinct. VAXen, Cray vector systems, and IBM
    mainframes all have their own floating-point formats predating the
    IEEE standards.

    It may (or may not) be possible for a future C standard to mandate
    that all-bits-zero is a valid representation of 0.0 for floating-point
    types. Mandating IEEE format won't be practical for a long time, if
    ever.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jun 17, 2004
    #19
  20. In article <>,
    Keith Thompson <> wrote:

    >But it's certainly not the case that all computers out there are using
    >IEEE-754 or IEE-854. Non-IEEE representations are becoming less
    >common, but there's not extinct. VAXen, Cray vector systems, and IBM
    >mainframes all have their own floating-point formats predating the
    >IEEE standards.


    True, but do any of the ones you mention not have all-bits-zero -> 0.0?

    -- Richard
     
    Richard Tobin, Jun 18, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi Donatello Asero

    Let or not let the text float

    Luigi Donatello Asero, Jan 15, 2004, in forum: HTML
    Replies:
    6
    Views:
    494
    Steve R.
    Jan 15, 2004
  2. Sydex
    Replies:
    12
    Views:
    6,646
    Victor Bazarov
    Feb 17, 2005
  3. bd
    Replies:
    0
    Views:
    663
  4. Replies:
    26
    Views:
    2,369
    Chris Croughton
    Jul 23, 2005
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,648
    James Kanze
    Oct 8, 2009
Loading...

Share This Page