help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

g++ 3.4.2 strange behavior


From: Paul Schneider
Subject: g++ 3.4.2 strange behavior
Date: Mon, 01 Nov 2004 19:18:44 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041009

Hello,

I'm very confused by the output of the following program compiled with g++ 3.4.2 in Gentoo Linux:

#include <iostream>
#include <cstdlib>

using std::cout;
using std::endl;

class Hello {
public:
Hello(double a, double b, double c) : aNumber(static_cast<size_t>((b-a)/c)){}
        size_t const number() const { return aNumber; }
        private:
                size_t const aNumber;
};



int main(int argc, char *argv[])
{
        Hello hello(0.0, 1000.0, 0.01);
  cout << hello.number()  << endl;
  cout << static_cast<size_t>((1000.0 / 0.01)) << endl;
  cout << static_cast<size_t>((1000.0 - 0.0) / 0.01) << endl;

  return EXIT_SUCCESS;
}

TThe output:
99999
100000
100000

where it should be 100000 straight in my opinion. What am I doing wrong.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]