# strictfp keyword

manasa teja

Ranch Hand

Posts: 325

James Hobson

Ranch Hand

Posts: 140

posted 14 years ago

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

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

Posts: 46

posted 14 years ago

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

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