3

Does the Java Standard impose anything about the exact behavior of floating points?

Is there any guaranty that it will use de-normalized numbers? There are the constants Float.MIN_VALUE and Float.MIN_NORMAL, but what happens when the hardware does not handle de-normalized numbers?

In a more concrete case, am I guarantied that on a x86/64 system that every java implementation does not disable de-normalized values?

Can I disable this behavior and consider all de-normalized numbers as zero?

Unlikus
  • 1,419
  • 10
  • 24
  • Floating-point numbers in Java follow the [IEEE 754 standard](https://en.wikipedia.org/wiki/IEEE_754) as defined in [JLS §4.2.3](https://docs.oracle.com/javase/specs/jls/se14/html/jls-4.html#jls-4.2.3). – Turing85 Aug 01 '20 at 11:20
  • 1
    To get deterministic behaviour with floating point arithmetic, use the (little known and rarely used) keyword [`strictfp`](https://stackoverflow.com/questions/517915/when-should-i-use-the-strictfp-keyword-in-java) – Bohemian Aug 01 '20 at 11:35

1 Answers1

3

The Java Language Specification section 4.2.4 requires support for denormalized numbers:

In particular, the Java programming language requires support of IEEE 754 denormalized floating-point numbers and gradual underflow, which make it easier to prove desirable properties of particular numerical algorithms. Floating-point operations do not "flush to zero" if the calculated result is a denormalized number.

If the hardware does not handle de-normalized numbers, this has to patched in software in the JVM for it to be compliant with the specification.

Joni
  • 108,737
  • 14
  • 143
  • 193