For floating point operations and expression intermediate values, a greater precision can be used than the type of the expression. Only the minimum precision is set by the types of the operands, not the maximum. Implementation Note: On Intel x86 machines, for example, it is expected (but not required) that the intermediate calculations be done to the full 80 bits of precision implemented by the hardware.
It's possible that, due to greater use of temporaries and common subexpressions, optimized code may produce a more accurate answer than unoptimized code.
Algorithms should be written to work based on the minimum precision of the calculation. They should not degrade or fail if the actual precision is greater. Float or double types, as opposed to the extended type, should only be used for:
This is all done to avoid adding a new type. Adding a new type means that the compiler
can make all the semantics of complex work "right". The programmer then can rely on a
correct (or at least fixable
Coming with the baggage of a complex type is the need for an imaginary type. An
imaginary type eliminates some subtle semantic issues, and improves performance by not
having to perform extra operations on the implied 0 real part.
Imaginary literals have an i suffix:
ireal j = 1.3i;
There is no particular complex literal syntax, just add a real and imaginary type:
cdouble cd = 3.6 + 4i;
creal c = 4.5 + 2i;
Complex numbers have two properties:
.re get real part
.im get imaginary part as an imaginary
For example:
cd.re is 4.5 double
cd.im is 2i idouble
c.re is 4.5 real
c.im is 2i ireal
Rounding Control
IEEE 754 floating point arithmetic includes the ability to set 4 different rounding modes.
D adds syntax to access them: [blah, blah, blah] [NOTE: this is perhaps better done with
a standard library call]
Exception Flags
IEEE 754 floating point arithmetic can set several flags based on what happened with a
computation: [blah, blah, blah]. These flags can be set/reset with the syntax: [blah, blah,
blah] [NOTE: this is perhaps better done with a standard library call]
Floating Point Comparisons
In addition to the usual < <= > >= == != comparison operators, D adds more that are
specific to floating point. These are [blah, blah, blah] and match the semantics for the
NCEG extensions to C.
[insert table here]
Copyright (c) 1999-2001 by Digital Mars, All Rights Reserved