Last active
March 17, 2016 14:34
-
-
Save cglosser/dfad193bad2c86e9cc23 to your computer and use it in GitHub Desktop.
Floating point c (mks)
This file contains hidden or 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 <iomanip> | |
#include <limits> | |
using namespace std; | |
#define PREC std::setprecision(std::numeric_limits<long double>::digits10 + 1) | |
int main() { | |
float c_float; | |
double c_dble; | |
cout << "Single precision" << endl; | |
c_float = 299792458; | |
cout << PREC << c_float << endl; | |
c_float = 299792458.0f; | |
cout << PREC << c_float << endl; | |
c_float = 299792458.0; | |
cout << PREC << c_float << endl; | |
cout << PREC << "Double precision" << endl; | |
c_dble = 299792458; | |
cout << PREC << c_dble << endl; | |
c_dble = 299792458.0f; | |
cout << PREC << c_dble << endl; | |
c_dble = 299792458.0; | |
cout << PREC << c_dble << endl; | |
return 0; | |
} |
This file contains hidden or 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
program test | |
implicit none | |
real(8) :: c_real | |
real :: c_flt | |
write(*,*) "Floating point" | |
c_flt = 299792458 | |
write(*,*) c_flt | |
c_flt = 299792458.0 | |
write(*,*) c_flt | |
c_flt = 299792458d0 | |
write(*,*) c_flt | |
write(*,*) "Double precision" | |
c_real = 299792458 | |
write(*,*) c_real | |
c_real = 299792458.0 | |
write(*,*) c_real | |
c_real = 299792458d0 | |
write(*,*) c_real | |
end program test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment