fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. int main() {
  5. long long int i=10000000000000;
  6. float f=100000000000000.0;
  7.  
  8. auto x = i*f; // does not account for expected change of scale
  9. std::cout <<"Type "<< typeid(x).name() <<": "
  10. <<std::fixed <<std::setw(30) << x << std::endl;
  11.  
  12. long double y = i*(long double)f; // without casting, same as before
  13. std::cout <<"Type "<< typeid(y).name() <<": "
  14. <<std::fixed <<std::setw(30) <<y << std::endl;
  15. // remaining rounding error is because of the initial float.
  16. // Correcting the original variable with long double and using auto gives better result !!!
  17. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Type f: 999999988484154753734934528.000000
Type e: 1000000003768320000000000000.000000