# Strictfp why i cant use???

Mohammed Yousuff

Ranch Hand

Posts: 198

posted 8 years ago

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...

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 : http://passion4java.blogspot.com

Try not to become a man of success but rather to become a man of value.

Campbell Ritchie

Marshal

Posts: 52590

119

posted 8 years ago

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!

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

Posts: 198

posted 8 years ago

thanks Campbell for your comments.

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

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

Try not to become a man of success but rather to become a man of value.

William Brogden

Author and all-around good cowpoke

Rancher

Rancher

Posts: 13078

6

posted 8 years ago

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.

Bill

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.

Bill

posted 8 years ago

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:

8.1.1.3 - strictfp Classes

8.4.3.5 - strictfp Methods

9.1.1.2 - 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 ]

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:

8.1.1.3 - strictfp Classes

8.4.3.5 - strictfp Methods

9.1.1.2 - 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 ]

Consider Paul's rocket mass heater. |