Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strictfp why i cant use???

 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic