Home  >  Article  >  Backend Development  >  How to Emulate Double-Precision Arithmetic Using Single-Precision Floats?

How to Emulate Double-Precision Arithmetic Using Single-Precision Floats?

Linda Hamilton
Linda HamiltonOriginal
2024-11-02 12:24:30629browse

 How to Emulate Double-Precision Arithmetic Using Single-Precision Floats?

Emulating Double-Precision Arithmetic with Floats

In certain scenarios, embedded hardware systems with limited floating-point support may encounter the need for double-precision functionality. This raises the question of how to achieve this using only single-precision floating-point operations.

To emulate a double-precision value, the approach is to utilize a struct containing a tuple of two single-precision floats, representing the high and low portions of the double. The comparison can be performed using lexicographic ordering.

However, the addition operation presents a challenge. The base for the addition should be carefully considered to ensure accuracy. It is recommended to use a multiple of FLT_MAX (the maximum value representable by a single-precision float) to avoid intermediate underflow or overflow.

To detect a carry, one can subtract the sum of the two floats from the expected value. If the result is less than or equal to zero, a carry has occurred.

The references below provide valuable insights into techniques for double-precision emulation using single-precision floats on GPU architectures:

  • https://hal.archives-ouvertes.fr/hal-00021443
  • http://andrewthall.org/papers/df64_qf128.pdf

The above is the detailed content of How to Emulate Double-Precision Arithmetic Using Single-Precision Floats?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn