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 a real
For example:
cd.re is 4.5 double
cd.im is 2 double
c.re is 4.5 real
c.im is 2 real
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
!<>=
<>
<>=
!<=
!<
!>=
!>
!<>
and match the semantics for the
NCEG extensions to C.
Floating point comparison operators
Operator Relations Invalid? Description
> < = ?
< F T F F yes less than
> T F F F yes greater than
<= F T T F yes less than or equal to
>= T F T F yes greater than or equal to
== F F T F no equal to
!= T T F T no unordered, less than, or greater than
!<>= F F F T no unordered
<> T T F F yes less than or greater than
<>= T T T F yes less than, equal to, or greater than
!<= T F F T no unordered or greater than
!< T F T T no unordered, greater than, or equal to
!>= F T F T no unordered or less than
!> F T T T no unordered, less than, or equal to
!<> F F T T no unordered or equal to
Feedback and Comments
Add feedback and comments regarding this
page.
Copyright (c) 1999-2004 by Digital Mars, All Rights Reserved