David's final changes: more profiler features, fixes.
[ipdf/code.git] / src / tests / paranoidcalculator.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 #include "paranoidnumber.h"
11
12 using namespace std;
13 using namespace IPDF;
14
15 int main(int argc, char ** argv)
16 {
17         Debug("FLT_MAX = %.40f", FLT_MAX);
18         Debug("FLT_MIN = %.40f", FLT_MIN);
19         Debug("FLT_EPSILON = %.40f", FLT_EPSILON);
20         Debug("Sizeof ParanoidNumber::digit_t is %u", sizeof(ParanoidNumber::digit_t));
21         Debug("Sizeof ParanoidNumber is %u", sizeof(ParanoidNumber));
22         Debug("Sizeof double is %u", sizeof(double));
23         Debug("Sizeof ParanoidNumber* %u", sizeof(ParanoidNumber*));
24
25         string token("");
26         cin >> token;   
27         ParanoidNumber a(token.c_str());
28         double da = a.ToDouble();
29         float fa = da;
30         while (cin.good())
31         {
32                 Debug("a is {%s} \"%.40lf\"", a.Str().c_str(), a.ToDouble());
33                 char op;
34                 cin >> op;
35                 token = "";
36                 for (char c = cin.peek(); cin.good() && !iswspace(c); c = cin.peek())
37                 {
38                         if (c == '+' || c == '-' || c == '*' || c == '/')
39                         {
40                                 break;
41                         }
42                         token += c;
43                         c = cin.get();
44                 }
45                 
46                 //Debug("String is \"%s\"", token.c_str());
47                 float fb = strtof(token.c_str(), NULL);
48                 double db = strtod(token.c_str(), NULL);
49                 ParanoidNumber b(token.c_str());
50         
51                 Debug("b is {%s} \"%lf\"", b.Str().c_str(), b.ToDouble());
52                 Debug("db is %lf", db);
53                 switch (op)
54                 {
55                         case '+':
56                                 a += b;
57                                 fa += fb;
58                                 da += db;
59                                 break;
60                         case '-':
61                                 a -= b;
62                                 fa -= fb;
63                                 da -= db;
64                                 break;
65                         case '*':
66                                 a *= b;
67                                 fa *= fb;
68                                 da *= db;
69                                 break;
70                         case '/':
71                                 a /= b;
72                                 fa /= fb;
73                                 da /= db;
74                                 break;
75                 }
76                         
77                 Debug("a is: {%s}", a.Str().c_str());
78                 Debug("a as double: %.40lf", a.ToDouble());
79                 //Debug("a as float: %.40f", a.ToFloat());
80                 //Debug("a as int64_t: %ld", a.Convert<int64_t>());
81                 //Debug("floats give: %.40f", fa);
82                 Debug("double gives: %.40lf", da);
83                 
84                 
85         }
86 }

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