0

Take the following code in c++

#include <iostream>
#include <math.h> 
using namespace std; 

int main(){
  double one, out;
 
  one = (pow(10, 10) - 1 ) / 9; //1111111111 
  out = one  * pow(10, 12) + one * 80 + 9;
  cout << fixed << out << endl;
}

it returns

1111111111088888872960.000000

Variable out should equal 1111111111088888888889.
When I paste the following formula in https://www.wolframalpha.com, that equals varialble one
(10^10 - 1)/9 * 10^12 + 80 * (10^10 - 1)/9 + 9 the result is correct. Could you tell me where I did a mistake?

regor
  • 27
  • 6

0 Answers0