We need to clarify if 'real' is the 'default floating point type' or not.

Don Clugston dac at nospam.com.au
Tue Mar 4 00:09:28 PST 2008


Don Clugston wrote:
> The spec is not quite clear on what 'real' can be and when it should be 
> used.
> For DMD, 'real' is the 80-bit (actually 79bit) X87 extended 
> floating-point type. This has the following characteristics:
> a. it is the highest precision floating-point type supported by the 
> hardware;
> b. it is the highest precision floating-point type which is fast;
> c. it is almost as fast as double;
> d. it is the precision used internally for all floating point 
> calculations (And this makes it the only precision which is anomoly-free).
> e. it is an IEEE floating-point type.
> 
> In the spec, 'real' is defined as the "largest hardware implemented 
> floating point size (Implementation Note: 80 bits for Intel CPUs)", so 
> we can apparently rely on (a); but unfortunately, that's not enough to 
> give us usage rules.

Actually, it wouldn't be necessary to create type names for all the different 
variations of real (except perhaps quad).

A possible solution:

Change the 'real' keyword into '__real'. Name mangling unchanged.

Add

version(X86) {
  alias __real real;
} else {
  alias double real;
}

into std.object.
(Or should the second one be a typedef? I'm not sure).

Then we have the design rules:
* use 'real' everywhere, except in arrays and I/O.
* use __real when you want as much precision as possible, and you don't care how 
  much precision that is.

Yes, __real looks like a wierd, non-portable, OS-specific type. And that's what 
it is.
'real' looks like the type you should use by default.



More information about the Digitalmars-d mailing list