Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > memset all bits to zero will let float/double to zero?

Reply
Thread Tools

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

 
 
Zhiqiang Ye
Guest
Posts: n/a
 
      06-16-2004
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.


 
Reply With Quote
 
 
 
 
Grumble
Guest
Posts: n/a
 
      06-16-2004
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.

 
Reply With Quote
 
 
 
 
Dan Pop
Guest
Posts: n/a
 
      06-16-2004
In <cap8jq$2kb1$(E-Mail Removed)99.com> "Zhiqiang Ye" <(E-Mail Removed)> 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: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      06-16-2004
In article <cap8jq$2kb1$(E-Mail Removed)99.com>,
Zhiqiang Ye <(E-Mail Removed)> 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
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      06-16-2004
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-newsgrou...mp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      06-16-2004
In <cap9fg$8sj$(E-Mail Removed)> Grumble <(E-Mail Removed)> 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: (E-Mail Removed)
 
Reply With Quote
 
Erik Trulsson
Guest
Posts: n/a
 
      06-16-2004
Zhiqiang Ye <(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      06-16-2004
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

 
Reply With Quote
 
Gordon Burditt
Guest
Posts: n/a
 
      06-16-2004
>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

 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      06-16-2004
In article <cap8jq$2kb1$(E-Mail Removed)99.com>,
"Zhiqiang Ye" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is a pointer memset to zero necessarily eqal to NULL? viza C Programming 17 07-09-2008 09:07 AM
Can "all bits zero" be a trap representation for integral types? Army1987 C Programming 6 07-07-2007 12:01 PM
is it safe to zero float array with memset? 69dbb24b2db3daad932c457cccfd6@gmail.com C Programming 26 07-23-2005 11:41 AM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM



Advertisments