javastrictfp

what is the use of strictfp non- access modifier?


I know this is a duplicate question. but i want know it with an example. so can anyone explain it with an example?

Link to duplicate post: When should I use the "strictfp" keyword in java?


Solution

  • Well, girinie's answer sums it up nicely, but if you're looking for an example ..

    Let's say you made a game which allows for highscore submissions, but only after the server validates the score. One method to validate the score is to have the client send the keypresses (and their timestamps) to the server. Ideally the server would then play through the exact same game and obtain the same score.

    Now, let's say your game has some physics that can alter the outcome of the game (e.g. an explosion throwing random debris which COULD hurt you, if it hits).

    The physics of that game potentially could be different on the server (even if it's only slightly) than the client (e.g., if converting to integers for collision detection, it was rounded down instead of up). On an edge case like that, you could have a situation where the client game was not hit by debris from the explosion, but the server game was - and now you have a difference in score, which could incorrectly invalidate a highscore submission

    While strictfp is certainly not a silver bullet, it goes a long way in imposing some consistency of 'replaying' instructions across different platforms.