Float question - different compilers

C

cru

I have a question in regard to floating point calculation behavior
that exists between different compilers on the same hardware. Say, the
difference between a console app written in windows using visaul c++
vs. linux and gcc. I seem to recall running into problems with this in
the past (floating point calculations using different compilers) but I
can't come up with a simple yet concrete example. Any small snippet of
code that exhibits different behavior in regard to floating point
calculations on different compilers would be helpful. Or am I simply
imagining things and there really are no differences?
 
V

Victor Bazarov

cru said:
I have a question in regard to floating point calculation behavior
that exists between different compilers on the same hardware. Say, the
difference between a console app written in windows using visaul c++
vs. linux and gcc. I seem to recall running into problems with this in
the past (floating point calculations using different compilers) but I
can't come up with a simple yet concrete example. Any small snippet of
code that exhibits different behavior in regard to floating point
calculations on different compilers would be helpful. Or am I simply
imagining things and there really are no differences?

Quite possible. But don't let that stop you. If _you_ find some "small
snippet of code that exhibits", let us know. In all I've seen there are
no differences.

Victor
 
R

Ralf Schneeweiß

Hi,

some compilers are converting float internally to double. The following code
will detect this:

#include <iostream>
int main()
{
float fnum = 7.7;
double dnum = 7.7;

double d1 = fnum; // !!!
double d2 = dnum; // !!!

if( d1 == d2 )
std::cout << "The values are equal." << std::endl;
else
std::cout << "The values are NOT equal." << std::endl;

return 0;
}


Ralf
www.oop-trainer.de
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top