Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying IEEE-754 quadruple-precision (binary128) floating point values in scientific notation in C#

I'm trying to translate the raw binary data from a thread context into a human-readable format, and have come up empty when trying to translate quadruple-precision floating point values into a readable format in C#.

Ultimately, I'd like to display it in standard scientific notation, e.g. 1.234567×1089. I'm not worried about loss of precision in the process - I just want a reasonable idea of what the value is.

My first thought was to manually compute the value as a double by raising the exponent, but of course I'm going to exceed the maximum value in many cases. I don't mind losing precision, but not being able to display it at all isn't acceptable.

Is there some kind of simple mathematical hack I can use for this?

like image 530
Polynomial Avatar asked Apr 07 '14 16:04

Polynomial


People also ask

How are floating-point numbers represented in C?

Any number that has a decimal point in it will be interpreted by the compiler as a floating-point number. Note that you have to put at least one digit after the decimal point: 2.0, 3.75, -12.6112. You can specific a floating point number in scientific notation using e for the exponent: 6.022e23.

How many digits is quadruple precision?

In computing, quadruple precision (or quad precision) is a binary floating point–based computer number format that occupies 16 bytes (128 bits) with precision at least twice the 53-bit double precision.

What is the format of the single precision floating point format IEEE 754?

The format of IEEE single-precision floating-point standard representation requires 23 fraction bits F, 8 exponent bits E, and 1 sign bit S, with a total of 32 bits for each word. F is the mantissa in 2's complement positive binary fraction represented from bit 0 to bit 22.

How many precisions are available under IEEE 754 standard of FP numbers?

The IEEE 754 standard specifies two precisions for floating-point numbers. Single precision numbers have 32 bits − 1 for the sign, 8 for the exponent, and 23 for the significand.


1 Answers

You could install a third-party library that handles that. For example it looks like QPFloat gives you a new struct called System.Quadruple which overrides ToString, so you could try that.

(I wonder when .NET will support something like System.Quadruple.)

like image 97
Jeppe Stig Nielsen Avatar answered Sep 28 '22 16:09

Jeppe Stig Nielsen