Skip to content

Instantly share code, notes, and snippets.

@cglosser
Last active March 17, 2016 14:34
Show Gist options
  • Save cglosser/dfad193bad2c86e9cc23 to your computer and use it in GitHub Desktop.
Save cglosser/dfad193bad2c86e9cc23 to your computer and use it in GitHub Desktop.
Floating point c (mks)
#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;
}
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