Handling a quadruple precision floating point (128-bit) number in java

user474762

I need to make use of numbers coming from another system that are 128-bit (quadruple-precision) floating point numbers in java.

Considering that there is no equivalent type in java, I would like to reduce the precision of the numbers using java code so they can be stored in a java double. This can be done fairly easily in c or using assembly but I would like to do it purely in java.

It is fair to assume that the quadruple-precision number is stored in a 128-bit byte array in java.

Is there a good solution, using only java? Thanks.

Glenn Lane

I was so intrigued by this question that I was compelled to write a library to handle IEEE-754 floating point numbers. With the library, you can use the following:

byte[] quadBytes; // your quad-floating point number in 16 bytes
IEEE754 quad = IEEE754.decode(IEEE754Format.QUADRUPLE, 
        BitUtils.wrapSource(quadBytes));
// IEEE754 holds the number in a 'lossless' format

From there, you can:

ByteBuffer doubleBuffer = ByteBuffer.allocateDirect(8);
quad.toBits(IEEE754Format.DOUBLE, BitUtils.wrapSink(doubleBuffer));
doubleBuffer.rewind();
double converted = doubleBuffer.asDoubleBuffer().get();

But the above snippet is just to illustrate general usage... a shorthand is provided for double:

double converted = quad.doubleValue();

The code is available at kerbaya.com/ieee754lib.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Handling a quadruple precision floating point (128-bit) number in java

From Dev

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

From Dev

How to increase the floating point precision of a number by using BigDecimals in java?

From Dev

Java Floating Point Precision Issue

From Dev

Handling Floating Point Number in Bash

From Dev

Python: forcing precision on a floating point number in json?

From Java

How to deal with floating point number precision in JavaScript?

From Dev

Abstracting floating point precision in java projects

From Dev

Double floating-point precision in Java

From Dev

Floating point precision with Math.Ceil (Java)

From Dev

What bit pattern represents the max value for double precision floating point?

From Dev

How can I move an 80-bit floating point number with double precision from memory to XMM0 in AT&T assembly

From Dev

Floating Point Precision Error

From Dev

a floating point precision of X

From Dev

precision of floating point in tensorflow

From Dev

Assembly - Round floating point number to .001 precision toward -∞

From Dev

what is it called when a floating point number is larger than its precision?

From Dev

Converting base of floating point number without losing precision

From Dev

Can you set the qDebug() floating point precision and number format globally?

From Dev

Converting base of floating point number without losing precision

From Dev

fast computation for extended precision floating point for number theory application

From Dev

Why precision problems in a floating point number varies according to values?

From Dev

How to rotate 128 bit number in Java

From Dev

Significant precision difference in floating point calculations in Java / C#

From Dev

Significant precision difference in floating point calculations in Java / C#

From Dev

Changing sign of a 64 bit floating point number in verilog?

From Dev

Floating point numbers precision in python

From Dev

Increasing floating point precision in Python

From Dev

Floating point numbers, precision, and Parsec

Related Related

  1. 1

    Handling a quadruple precision floating point (128-bit) number in java

  2. 2

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

  3. 3

    How to increase the floating point precision of a number by using BigDecimals in java?

  4. 4

    Java Floating Point Precision Issue

  5. 5

    Handling Floating Point Number in Bash

  6. 6

    Python: forcing precision on a floating point number in json?

  7. 7

    How to deal with floating point number precision in JavaScript?

  8. 8

    Abstracting floating point precision in java projects

  9. 9

    Double floating-point precision in Java

  10. 10

    Floating point precision with Math.Ceil (Java)

  11. 11

    What bit pattern represents the max value for double precision floating point?

  12. 12

    How can I move an 80-bit floating point number with double precision from memory to XMM0 in AT&T assembly

  13. 13

    Floating Point Precision Error

  14. 14

    a floating point precision of X

  15. 15

    precision of floating point in tensorflow

  16. 16

    Assembly - Round floating point number to .001 precision toward -∞

  17. 17

    what is it called when a floating point number is larger than its precision?

  18. 18

    Converting base of floating point number without losing precision

  19. 19

    Can you set the qDebug() floating point precision and number format globally?

  20. 20

    Converting base of floating point number without losing precision

  21. 21

    fast computation for extended precision floating point for number theory application

  22. 22

    Why precision problems in a floating point number varies according to values?

  23. 23

    How to rotate 128 bit number in Java

  24. 24

    Significant precision difference in floating point calculations in Java / C#

  25. 25

    Significant precision difference in floating point calculations in Java / C#

  26. 26

    Changing sign of a 64 bit floating point number in verilog?

  27. 27

    Floating point numbers precision in python

  28. 28

    Increasing floating point precision in Python

  29. 29

    Floating point numbers, precision, and Parsec

HotTag

Archive