FAQ

Java

JSP

Servlet


Advertisement



What does 'strictfp' mean?

The keyword strictfp allows you to have more (predictable) control over floating-point arithmetic. Different arithmetic/logic units may enable additional features which allow a machine dependent answer to a floating point problem. The Java Virtual Machine has been modified to allow Java implementations to use these features where developers are not concerned with a routine, possibly providing a different, ie: more *or* less accurate solution to a problem on differing architectures.

Because many developers want the exact same solution to occur regardless of the underlying hardware, the strictfp keyword was implemented. strictfp insures that the VMS will always use a standardized implementation of floating point numbers, wherever the application/applet is run. Thus continuity across platforms is achieved. When this modifier is specified, the JVM adheres to the Java specifications ( IEEE-754 floating-point specification ) and returns the consistent value independent of the platform.

It can be used as a modifier with top-level classes, both static and non-static inner classes, inner interfaces, both static and instance method declarations. Variables, constructors, static or instance floating blocks can't have this modifier.

If an expression is FP-strict, all intermediate values should fit into the range for float or double variables, implying that the results of all FP-strict expressions must be those predicted by IEEE 754 arithmetic on operands represented using single and double formats. If an expression is not FP-strict, there are no such restrictions.

A non-constant expression is considered FP-strict if any of the class, interface or method declarations that contain the expression have the strictfp modifier.

References

15.4 FP-strict Expressions in JLS3

Updates to the Java Language Specification for JDK Release 1.2 Floating Point


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |