Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an open-source c/c++ implementation of IEEE-754 operations? [closed]

I am looking for a reference implementation of IEEE-754 operations. Is there such a thing?

like image 686
zr. Avatar asked Feb 02 '10 19:02

zr.


People also ask

What is pitfalls of floating-point representation?

Inexact The “real” result of a computation cannot be exactly represented by a floating-point number. The silent response is to round the number, which is a behaviour that the vast majority of programs using floating-point numbers rely upon. However, rounding has to be correctly taking into account for sound analysis.

What is the IEEE standard for floating-point operation?

The IEEE-754 standard describes floating-point formats, a way to represent real numbers in hardware. There are at least five internal formats for floating-point numbers that are representable in hardware targeted by the MSVC compiler. The compiler only uses two of them.

Why IEEE 754?

IEEE developed the IEEE 754 floating-point standard. This standard defines set formats and operation modes. All computers conforming to this standard would always calculate the same result for the same computation. This standard does not specify arithmetic procedures and hardware to be used to perform computations.

What can be the maximum value which can be represented in IEEE 754 single precision floating-point representation?

A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2−23) × 2127 ≈ 3.4028235 × 1038.


3 Answers

I believe the C libraries SoftFloat and fdlibm are suitable for what you are looking for. Others include Linux (GNU libc, glibc) or *BSD libc's math functions. Finally, CRlibm should also be of interest to you.

Ulrich Drepper has a interesting look at different math libraries, that might be also worth reading through.

like image 112
mctylr Avatar answered Oct 10 '22 16:10

mctylr


I must disappoint you: There is practically none.

While technically there are IEEE-754 compliant systems because they do not implement non-required features described in the standard, a reference implementation allowing

  • access to all rounding modes
  • support signalling NaNs
  • support trapping of all five traps

does not exist in the standard languages. This causes recurring woes of William Kahan, the main force behind the standard and its adaption on the Intel processors.

I don't know if there are some esoteric languages which do support them, but I can rule out Java, C#, C++, Fortran.

EDIT: While there is a lack of compiler support, I advise Hausers SoftFloat implementation given by mctylr. Hauser knows what he is doing.

http://portal.acm.org/citation.cfm?id=227699.227701&coll=portal&dl=ACM&CFID=77938829&CFTOKEN=18578907

like image 40
Thorsten S. Avatar answered Oct 10 '22 15:10

Thorsten S.


A rather confusing question; in C++ it is assumed this sort of detail is taken care of by the hardware or the compiler. So, in C++ floating-point addition would be

float a = 1.0;
float b = 2.0;
float c = a + b;

I'm sure this is not what you actually meant; perhaps you'd benefit from this page which tries to emulate IEEE-754-compliant hardware in javascript?

like image 33
BlueRaja - Danny Pflughoeft Avatar answered Oct 10 '22 16:10

BlueRaja - Danny Pflughoeft