Prajwal Kumar
Prajwal Kumar

Reputation: 177

C++ Floating point difference

I am trying to get exact same results on 2 different platform i.e. Solaris and Linux(sun-studio vs GCC). The entire code uses double datatype. But when i print the output i see differences in the floating point(like in the 20th decimal place).

What i need to know is whether i can set some compiler flag to make both GCC and sun-studio compiler behave equally. Attached Image shows difference in Double datatype. Left side is the Output from GCC and other one is from sun-studio.

enter image description here

Upvotes: 3

Views: 697

Answers (1)

luizinho
luizinho

Reputation: 126

The main issue comes from this :

I am trying to get exact same results on 2 different platform

You are not guaranteed that you will have the same results on two different platforms. They may differ on so many ways on how they implement floating operations.

One solution to your problem: fixed-point arithmetic.

Also, take a look at these answers :

Cross Platform Floating Point Consistency

Are IEEE float and double guaranteed to be the same size on any OS?

They are a quite good start for you to understanding what is going on.

Upvotes: 9

Related Questions