X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Ftests%2Fparanoidcalculator.cpp;h=b9bd13a9fb1cbcbabffaf93d55b415949ea8b9c5;hp=171eaf08398a9103be6a5c15bd906e1178adb7bf;hb=bb659698bba26042232c038065b7edaa72541f61;hpb=6472d20ee58d2ecc0aee8bc1a12a071b2afc8a27 diff --git a/src/tests/paranoidcalculator.cpp b/src/tests/paranoidcalculator.cpp index 171eaf0..b9bd13a 100644 --- a/src/tests/paranoidcalculator.cpp +++ b/src/tests/paranoidcalculator.cpp @@ -17,19 +17,37 @@ int main(int argc, char ** argv) Debug("FLT_MAX = %.40f", FLT_MAX); Debug("FLT_MIN = %.40f", FLT_MIN); Debug("FLT_EPSILON = %.40f", FLT_EPSILON); - - ParanoidNumber a("0.3"); - Debug("start at %s", a.Str().c_str()); - cout << "0.3 "; - float fa = 0.3; - double da = 0.3; + Debug("Sizeof ParanoidNumber::digit_t is %u", sizeof(ParanoidNumber::digit_t)); + Debug("Sizeof ParanoidNumber is %u", sizeof(ParanoidNumber)); + Debug("Sizeof double is %u", sizeof(double)); + Debug("Sizeof ParanoidNumber* %u", sizeof(ParanoidNumber*)); + + string token(""); + cin >> token; + ParanoidNumber a(token.c_str()); + double da = a.ToDouble(); + float fa = da; while (cin.good()) { char op; - double db; - cin >> op >> db; - float fb(db); - ParanoidNumber b(fb); + cin >> op; + token = ""; + for (char c = cin.peek(); cin.good() && !iswspace(c); c = cin.peek()) + { + if (c == '+' || c == '-' || c == '*' || c == '/') + { + break; + } + token += c; + c = cin.get(); + } + //Debug("String is \"%s\"", token.c_str()); + float fb = strtof(token.c_str(), NULL); + double db = strtod(token.c_str(), NULL); + ParanoidNumber b(token.c_str()); + Debug("a is {%s} \"%lf\"", a.Str().c_str(), a.ToDouble()); + Debug("b is {%s} \"%lf\"", b.Str().c_str(), b.ToDouble()); + Debug("db is %lf", db); switch (op) { case '+': @@ -54,10 +72,12 @@ int main(int argc, char ** argv) break; } - Debug("a is: %s", a.Str().c_str()); - Debug("a as double: %.40f\n", a.ToDouble()); - Debug("floats give: %.40f\n", fa); - Debug("double gives: %.40f\n", da); + Debug("a is: {%s}", a.Str().c_str()); + Debug("a as double: %.40lf", a.ToDouble()); + Debug("a as float: %.40f", a.ToFloat()); + Debug("a as int64_t: %ld", a.Convert()); + Debug("floats give: %.40f", fa); + Debug("double gives: %.40lf", da); }