mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
32 lines
770 B
C++
32 lines
770 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2019-2020 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** point3.cxx : about truncation to float
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
using std::cin, std::cout;
|
|
|
|
int main() {
|
|
|
|
//codesnippet truncvsf
|
|
double point3d = .3/.7;
|
|
float
|
|
point3f = .3f/.7f,
|
|
point3t = point3d;
|
|
cout << "double precision: "
|
|
<< point3d << '\n'
|
|
<< "single precision: "
|
|
<< point3f << '\n'
|
|
<< "difference with truncation:"
|
|
<< point3t - point3f
|
|
<< '\n';
|
|
//codesnippet end
|
|
|
|
return 0;
|
|
}
|