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

Z

Zhiqiang Ye

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.
 
G

Grumble

Zhiqiang said:
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.
 
D

Dan Pop

In said:
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
 
R

Richard Tobin

Zhiqiang Ye said:
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
 
C

Chris Dollin

Zhiqiang said:
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.
 
D

Dan Pop

In said:
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
 
E

Erik Trulsson

Zhiqiang Ye said:
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.
 
A

Andrey Tarasevich

Zhiqiang said:
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.
 
G

Gordon Burditt

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
 
C

Christian Bau

"Zhiqiang Ye said:
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.
 
E

E. Robert Tisdale

Zhiqiang said:
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.
 
K

Keith Thompson

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.
 
K

Keith Thompson

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?
 
C

CBFalconer

E. Robert Tisdale said:
.... 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?
 
R

Ross Kendall Axe

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Keith Thompson wrote:
| (e-mail address removed) (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-----
 
A

Anarchist

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
 
D

Dan Pop

In said:
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
 
D

Dan Pop

In said:
(e-mail address removed) (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
 
K

Keith Thompson

Anarchist said:
<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.
 
R

Richard Tobin

Keith Thompson said:
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
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top