Connecting Tech Pros Worldwide Forums | Help | Site Map

Float question - different compilers

cru
Guest
 
Posts: n/a
#1: Jul 19 '05
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?

Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Float question - different compilers


"cru" <crucpp@yahoo.com> wrote...[color=blue]
> 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?[/color]

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


Ralf Schneeweiß
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Float question - different compilers


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



Closed Thread