• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strictfp why i cant use???

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic