This week's book giveaway is in the Android forum. We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line! See this thread for details.

It doesn't apply to a variable, but to a calculation. You use it as a modifier for a method which means all arithmetic inside that method is restricted to the exact bounds of 32 and 64 bits. I think you can use it as a modifier for a class which means all methods are strictfp as well.

I have never managed to see a difference when I have tried strictfp arithmetic myself!

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198

posted

0

thanks Campbell for your comments.

Will strictfp variable will used in the financial calculations, how much they are extensively used ?

You have missed the point - Java floating point variables are not different when strictfp is used to label a calculation - it is the very subtle rounding/overflow effects in the calculation that are affected.

As I recall, the strictfp tag was introduced to force compatibility with mathematical processing in other languages. A calculation done with strictfp is slower, so there is no need to use it except when you are trying to exactly match results from other languages.

Originally posted by Mohammed Yousuff: Will strictfp variable will used in the financial calculations, how much they are extensively used ?

No, because the float and double data types are not suited for financial calculations. These datatypes have limited precision and will cause rounding errors when you do calculations with them, which is unacceptable for financial calculations. The strictfp modifier doesn't change anything about that.

You need something like class BigDecimal for financial calculations.

I think that strictfp is only very rarely used, it's only necessary for specialized applications that need floating point arithmethic which strictly adheres to the IEEE 754 standard, for example for some scientific calculations.

And especially see section 15.4 which explains exactly what it means if an expression is FP-strict. [ April 21, 2008: Message edited by: Jesper Young ]