my dog learned polymorphism
The moose likes Java in General and the fly likes Strictfp  why i cant use??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Strictfp  why i cant use???" Watch "Strictfp  why i cant use???" New topic

Strictfp why i cant use???

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
Can you please share me in which scenario we will use Strictfp ....

Why this variable can't be used with a instance variable....

the objective of the Strictfp is to return value which are IEEE standards, so why this cant be used with variables..

any thoughts...

My Thoughts :
Try not to become a man of success but rather to become a man of value.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46360
It's strictfp, not Strictfp.

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
thanks Campbell for your comments.

Will strictfp variable will used in the financial calculations, how much they are extensively used ?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Will strictfp variable

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.

See the Wikipedia discussion.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15083

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.

For more info on strictfp, see these sections in The Java Language Specification: - strictfp Classes - strictfp Methods - strictfp Interfaces

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 ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Strictfp why i cant use???
It's not a secret anymore!