type comparisons

"Jérôme M. Berger" jeberger at free.fr
Sat Jan 26 11:40:41 PST 2008


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

Denton Cockburn wrote:
> On Sat, 26 Jan 2008 18:36:41 +0000, BCS wrote:
> 
>> Reply to Denton,
>>
>>> [quoted text muted]
>> rounding error?
>>
>> rounding 0.6584 (base 10) to real and then converting to double may round 
>> different than rounding it directly to double.
> 
> I can't think of a reason that would be acceptable.
> This means I can't reliably do operations with converted reals/doubles :(
> 
> This is also weird:
> double a = 0.65;
> real b = a + 0.1;
	Here, you're computing "a + 0.1" using double, then converting it
to real

> b -= 0.1;
> assert(b == a); // fails
> 
> real c = a;
> c += 0.1;
	Here, you converted a to real, then you add 0.1 using real.

> c -= 0.1;
> assert(c == a); // passes

	Which could explain that rounding errors wind up different and make
one assertion pass while the other fails.

		Jerome
- --
+------------------------- Jerome M. BERGER ---------------------+
|    mailto:jeberger at free.fr      | ICQ:    238062172            |
|    http://jeberger.free.fr/     | Jabber: jeberger at jabber.fr   |
+---------------------------------+------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHm4y1d0kWM4JG3k8RAgfQAKC3LwsQfklEVT+cP2w3HrR/xtK6JACfdPr9
PQIwRTbf2zyhpst9zdeZn9s=
=RA4Q
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list