D language floating point operation

xiaoxiao2021-03-06  18

floating point

The floating point operation intermediate value is on many computers, using higher precision operations, is not more expensive than using lower precision, so the highest accuracy of the internal temporary variable is used for numerical operations. The philosophy used here is not strong to unify the lowest accuracy of various hardware, so that the best performance of the target hardware is taken.

For the intermediate value of floating point calculations, it may be used as the accuracy required to be higher than the expression type. The type of operand only determines the lowest accuracy instead of the highest accuracy. Implementation: For example, on the Intel X86 machine, the calculated intermediate step is preferably (but not required) uses all 80-bit precision provided by the hardware.

If the temporary variables and public sub-expression are used, optimized code is likely to be more accurate than unopened code.

The algorithm should be based on the minimum accuracy of the calculation. If the actual accuracy is higher, they should not degenerate or fail. Unlike the type of extension, Float or Double type should be used:

Reduce the compatibility of memory consumption of large arrays to maintain the same C's data and function parameters

Negative and imaginary types In existing languages, in order to add complex types to the existing type system, it is possible to exceed the existence of the turnover: template, structure, operator overload, etc., and the final result is almost failed. The reason for failure may be due to the semantics of the complex operation, because the compiler does not understand what the programmer wants to do, so it cannot be optimized.

All these purposes are just to avoid joining a new type. Adding a new type means that the compiler can make all the complex semantics work "normal". The programmer can then rely on the correct (at least stable) implementation of the plurality of complexes.

Along with the demand for imaginary numbers. Imaginary types are we can avoid some subtle semantic issues, and because you don't have to handle implicit 0 realms, you can improve the performance of the operation.

Immigrable text volume has one I as a suffix:

IREAL J = 1.3i;

The plural volume is not a special syntax, just write a real type and the imaginary type, you can add:

CDOUBLE CD = 3.6 4i;

CREAL C = 4.5 2i;

There are two attributes:

Real part

.im ingredient

E.g:

Cd.re is 4.5 DOUBLE

CD.IM is 2 Double

C.RE is 4.5 REAL

C.IM is 2 real

Fixing Control IEEE 754 floating point count arithmetic includes setting four different hiejun modes. D joins the syntax that supports them: [Blah, Blah, Blah] [Notes: Maybe the standard library is better]

Abnormal Symbol IEEE 754 floating-point count Math can set a logo for the incident occurring in the calculation: [Blah, Blah, Blah] These marks can be set as follows / reset: [Blah, Blah, Blah] [Notes: Perhaps the standard Better in the library]

In addition to common <, <=,>,> =, ==, and! = Comparison operators, D additionally provides an operator dedicated to floating point. They are! <> =, <>, <> =,! <= ,! <,!> = ,!>, and! <>, And conform to the semantics of the C-extended NCEG.

Floating point comparison operator operator relationship is invalid? description

> <=?

> T f f yes is greater than

<= F T t f yes less than or equal to

> = T f t f Yes is greater than or equal to

== f f NO is equal to

! = T t f T N is not defined, less than or greater than

! <> = F f f T no defined <> t t f yes less than or greater than

<> = T t t f Yes is less than, equal to or greater than

! <= T f f T NO undefined or greater than

!

!> = F T f T NO undefined or less than

!> F T t N is undefined, less than or equal to

! <> F t t NO is not defined or equal to

转载请注明原文地址:https://www.9cbs.com/read-49702.html

New Post(0)