Lorfa

ImplicitTypeCasting

Apr 7th, 2021
1,444
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     unsigned long long power,incorrect,incorrect2,incorrect3,incorrect4,incorrect5;
  8.     unsigned long long correct,correct2,correct3,correct4;
  9.    
  10.     double power2,power3;  
  11.        
  12.     power = 7 * pow(10, 17); // outputs 700000000000000000
  13.     power2 = pow(10, 17); // outputs 100000000000000000.000000
  14.     power3 = 7.0 * pow(10, 17); // outputs 700000000000000000.000000
  15.    
  16.     printf ("printf_power     %lld\n", power);
  17.     printf ("printf_power2    %f\n", power2);
  18.     printf ("printf_power3    %f\n", power3);
  19.    
  20.     correct = 42105263157890000 + power; // outputs 742105263157890000
  21.     correct2 = 42105263157890000 + 700000000000000000; // outputs 742105263157890000
  22.     correct3 = 42105263157890000 + (unsigned long long)(7 * pow(10, 17)); // outputs 742105263157890000
  23.     correct4 = 42105263157890000 + power; // outputs 742105263157890000
  24.    
  25.     cout << "correct    " << correct << "." << endl;
  26.     cout << "correct2   " << correct2 << "." << endl;
  27.     cout << "correct3   " << correct3 << "." << endl;
  28.     cout << "correct4   " << correct4 << "." << endl;
  29.    
  30.     incorrect = 42105263157890000 + (7 * pow(10, 17)); // outputs 74210526315789048
  31.    
  32.     incorrect2 = 42105263157890000 + (7 * 100000000000000000.00); // outputs 74210526315789048
  33.    
  34.     incorrect3 = 42105263157890000 + (7.0 * 100000000000000000.00); // outputs 74210526315789048
  35.    
  36.     incorrect4 = 42105263157890000 + 700000000000000000.00; // outputs 74210526315789048
  37.    
  38.     incorrect5 = 42105263157890000.00 + 700000000000000000.00; // outputs 74210526315789048
  39.    
  40.     double incorrect6 = 42105263157890000.00 + 700000000000000000.00; // outputs 74210526315789048.000000  
  41.  
  42.     cout << "incorrect  " << incorrect << "." << endl;
  43.    
  44.     cout << "incorrect2 " << incorrect2 << "." << endl;
  45.    
  46.     cout << "incorrect3 " << incorrect3 << "." << endl;
  47.    
  48.     cout << "incorrect4 " << incorrect4 << "." << endl;
  49.    
  50.     cout << "incorrect5 " << incorrect5 << "." << endl;
  51.    
  52.     printf ("incorrect6 %f\n", incorrect6);
  53.  
  54.     return 0;
  55. }
  56.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×