NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/44875
The following reply was made to PR lib/44875; it has been noted by GNATS.
From: Alan Barrett <apb%cequrux.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: lib/44875
Date: Fri, 29 Apr 2011 20:46:24 +0200
On Mon, 18 Apr 2011, Martin Husemann wrote:
> Are there FP values that compare equal and still are
> distinguishable?
Yes. Positive zero and negative zero compare equal, yet are
distinguishable, in at least some floating point representations.
When I run this program:
#include <stdio.h>
int main(void)
{
double x = 0.0; /* positive zero */
double y = -1.0 * 0.0; /* negative zero */
printf("x = %g\n", x);
printf("y = %g\n", y);
printf("%s\n", (x == y ? "x == y" : "!(x == y)"));
return 0;
}
I get this output:
x = 0
y = -0
x == y
I can also imagine floating point representations in which
many values have multiple representations, analogous to the
correspondence in decimal between 1.0e0, 10.0e-1, and 0.1e1.
--apb (Alan Barrett)
Home |
Main Index |
Thread Index |
Old Index