Float question - different compilers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cru

    Float question - different compilers

    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

    #2
    Re: Float question - different compilers

    "cru" <crucpp@yahoo.c om> 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


    Comment

    • Ralf Schneeweiß

      #3
      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
      Seminare zur Softwareentwicklung




      Comment

      Working...