c16265c00aeb5116402fb37d141bea5c9d44955a
[ipdf/code.git] / src / tests / fecalculator.cpp
1 #include "main.h"
2 #include "real.h"
3 #include <cmath>
4 #include <cassert>
5 #include <list>
6 #include <bitset>
7 #include <iostream>
8 #include <cfloat>
9 #include <fenv.h>
10
11 using namespace std;
12 using namespace IPDF;
13
14 int main(int argc, char ** argv)
15 {
16         Debug("FLT_MAX = %.40f", FLT_MAX);
17         Debug("FLT_MIN = %.40f", FLT_MIN);
18         Debug("FLT_EPSILON = %.40f", FLT_EPSILON);
19         
20         while (cin.good())
21         {
22                 float a; float b;
23                 char op;
24                 feclearexcept(FE_ALL_EXCEPT);
25                 cin >> a >> op >> b;
26                 
27                 float c;
28                 feclearexcept(FE_ALL_EXCEPT);
29                 switch (op)
30                 {
31                         case '+':
32                                 c = a + b;
33                                 break;
34                         case '-':
35                                 c = a - b;
36                                 break;
37                         case '*':
38                                 c = a * b;
39                                 break;
40                         case '/':
41                                 c = a / b;
42                                 break;
43                 }
44                 if (fetestexcept(FE_OVERFLOW))
45                         Debug("Overflow occured");
46                 else if (fetestexcept(FE_UNDERFLOW))
47                         Debug("Underflow occured");
48                 else if (fetestexcept(FE_INEXACT))
49                         Debug("Inexact result");
50                         
51                 printf("%.40f\n", c);
52                 
53                 
54         }
55 }

UCC git Repository :: git.ucc.asn.au