mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
44 lines
1012 B
C++
44 lines
1012 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2016=2021 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** round.cxx : rounding behavior
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <limits>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
#include <cfenv>
|
|
|
|
int main() {
|
|
|
|
float f_point7;
|
|
double d_point7;
|
|
cin >> f_point7;
|
|
cin >> d_point7;
|
|
|
|
vector<int> roundings = {FE_TONEAREST, FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO};
|
|
for ( auto round : roundings ) {
|
|
fesetround(round);
|
|
double d_one7, d_zero7 = 0.7;
|
|
d_one7 = 1. + d_point7; d_zero7 = 0. + d_point7;
|
|
|
|
float f_one7, f_zero7;
|
|
f_one7 = 1.f + f_point7; f_zero7 = 0.f + f_point7;
|
|
|
|
cout
|
|
<< boolalpha << ( f_one7<d_one7 )
|
|
<< " "
|
|
<< boolalpha << ( f_zero7<d_zero7 )
|
|
<< '\n';
|
|
}
|
|
|
|
return 0;
|
|
}
|