www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - what happens when "real" == "double"

reply Benjamin Shropshire <ao pathlink.com> writes:
real is defined as the largest hardware supported FP type. How should a program 
determine if real provides more precision than double? 

option: 

is(real == double)
real.sizeof == double.sizeof
real.epsilon == double.epsilon
other.

Relevance Example:

normalizing a vector of doubles while avoiding rounding can be done using 
this code, but only if real is larger than double.

double x,y,z;

real sum = x*x + y*y + z*z;
sum = sqrt(sum);

x /= sum;
y /= sum;
z /= sum;

However, if real == double, somthing else must be done.
Jan 29 2007
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Benjamin Shropshire schrieb am 2007-01-29:
 real is defined as the largest hardware supported FP type. How should a
program 
 determine if real provides more precision than double?
Depending of what exactly "precision" is for you: (real.dig > double.dig) or (real.epsilon < double.epsilon) Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFvu/1LK5blCcjpWoRAvA7AJ9CzqGmE0uZ0gXaSgSRN5SgOfrzQQCfaGbL p9bpGJ94kw8sbeEHo3bKRpw= =iXHk -----END PGP SIGNATURE-----
Jan 29 2007