Last active
August 28, 2015 19:20
-
-
Save yuki2006/86fc17dfc4512079522f to your computer and use it in GitHub Desktop.
C++で、引数の指定によってはsqrt(平方根)の値が異なることがある。 ref: http://qiita.com/yuki2006/items/f9de35affb660e64e895
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <iomanip> | |
#include <assert.h> | |
using namespace std; | |
int main(){ | |
long long int calc = sqrt(static_cast<long double>(18014415152484098LL)); | |
cout << calc <<endl; | |
long long int calc2 = sqrt(static_cast<double>(18014415152484098LL)); | |
cout << calc2 <<endl; | |
long long int calc3 = sqrt(static_cast<long long int>(18014415152484098LL)); | |
cout << calc3 <<endl; | |
long long int calc4 = sqrt(18014415152484098LL); | |
cout << calc4 <<endl; | |
cout<<setprecision(20)<< 18014415152484098LL <<endl; | |
cout<<setprecision(20)<< static_cast<double>(18014415152484098LL) <<endl; | |
cout<<setprecision(20)<< static_cast<long double>(18014415152484098LL) <<endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134217789 | |
134217790 | |
134217790 | |
134217790 | |
18014415152484098 | |
18014415152484096 | |
18014415152484098 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment