GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes strictfp  keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "strictfp  keyword" Watch "strictfp  keyword" New topic
Author

strictfp keyword

manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
what is the use of this strictfp keyword?
thanks


MT
James Hobson
Ranch Hand

Joined: Aug 28, 2001
Posts: 140
It is used to control floating point behaviour.
By default, java will allow the processor to do any floating point math to the best of its ability (if it can use 128bit numbers for example it will) and then trim off any excess data from the right hand side (loss of precision).
This means that for different hardware, the rounding errors may not be the same if the length of internal floating point numbers are different.
strictfp constrains all the intermediate fp number to be of java length.
So, strictfp requires all fp math to be equivalent accross VMs, but it does hit performance.
James
Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
Hi,
strictfp simply means perform strict floating point calculations on the expression. I will try to explain what I understood from the defenitions.
Older jvm (Classic [interpreter]) used original virtual machine specification which calculated all the floating point operations strictly. ie if (a*b)/(c*d) where all or any are floating point numbers, the intermediate results obtained should also be withing the range of Float. ie The above expression will receive the expected result only if a*b<Float.MAX_VALUE and c*d<Float.MAX_VALUE.(Classic Jvm). Rather than truncated at the end, the intermediate results also gets truncated.
But in new Jvm (Hotspot VM), things are a little different. All the floating point operations are performed without intermediate bounds checking; only the final answer is truncated to fit within Float.MAX_VALUE.
By adding strictfp as class/method modifier, we may change the default behaviour(of new VMs) of floating point operations, to that of the old ones (like in Classic JVM interpreters).
This link could help u get more details.
http://www.javaworld.com/javaworld/jw-12-1998/jw-jbe-jvm.html
Please let me know, if u could find any corrections or additional information regarding the same.
regards Jacob
 
GeeCON Prague 2014
 
subject: strictfp keyword