floating point zero value from c-faq.com

  • Thread starter subramanian100in
  • Start date
S

subramanian100in

In

http://c-faq.com/malloc/calloc.html

comp.lang.c FAQ list · Question 7.31 is present.

In the answer to the question, part of the answer is

calloc's zero fill is all-bits-zero, and is therefore guaranteed to
yield the value 0 for all integral types (including '\0' for character
types). But it does not guarantee useful null pointer values (see
section 5 of this list) or floating-point zero values.

My Question on this:
Here it is mentioned that calloc's zero fill does not guarantee
floating-point zero values.
But when every bit of an object is set to zero, won't the object value
be zero ie can the floating point variable be non-zero ? I am unable
to understand this. If I require to learn about floating points to
understand this, can someone suggest links to good material on
floating points?

Thanks
 
D

Dik T. Winter

> But when every bit of an object is set to zero, won't the object value
> be zero ie can the floating point variable be non-zero ?

Yes, the floating point variable can be non-zero. It depends entirely
on how floating-point is represented. You will not encounter it on
your home computer, but there *do* exist machines where, indeed, such
a value is non-zero.
 
C

CBFalconer

Dik T. Winter said:
Yes, the floating point variable can be non-zero. It depends
entirely on how floating-point is represented. You will not
encounter it on your home computer, but there *do* exist machines
where, indeed, such a value is non-zero.

I believe the C committee did some research, and was unable to find
such a machine, at least with an existing C implementation. Thus
they intend to remove the clause that specifies zeroing memory will
not form a zero float value. The pointer restriction remains.
Correction/expansion welcomed.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
A

Al Balmer

In

http://c-faq.com/malloc/calloc.html

comp.lang.c FAQ list · Question 7.31 is present.

In the answer to the question, part of the answer is

calloc's zero fill is all-bits-zero, and is therefore guaranteed to
yield the value 0 for all integral types (including '\0' for character
types). But it does not guarantee useful null pointer values (see
section 5 of this list) or floating-point zero values.

My Question on this:
Here it is mentioned that calloc's zero fill does not guarantee
floating-point zero values.
But when every bit of an object is set to zero, won't the object value
be zero ie can the floating point variable be non-zero ?

Yes, it can, since there are many methods of representing floating
point numbers.

I am unable
to understand this. If I require to learn about floating points to
understand this, can someone suggest links to good material on
floating points?

Yes, to understand it, you will need to learn about floating point.
Try this for starters:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
K

Keith Thompson

CBFalconer said:
I believe the C committee did some research, and was unable to find
such a machine, at least with an existing C implementation. Thus
they intend to remove the clause that specifies zeroing memory will
not form a zero float value. The pointer restriction remains.
Correction/expansion welcomed.

I don't think that's correct.

Technical Corrigendum 2 (post-C99) added the following:

For any integer type, the object representation where all the bits
are zero shall be a representation of the value zero in that type.

Before that addition, I don't think it was possible for all-bits-zero
to represent an integer value other than 0, but it was possible for it
to be a trap representation.

I've never heard of a similar proposal for floating-point. (Didn't we
talk about this before?)
 
M

Mark McIntyre

I believe the C committee did some research, and was unable to find
such a machine, at least with an existing C implementation. Thus
they intend to remove the clause that specifies zeroing memory will
not form a zero float value. The pointer restriction remains.
Correction/expansion welcomed.

I don't think thats correct. I believe IEEE754 (or whatever) defines
zero as a special case all-bits-zero, but its not obligatory.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top