%description: Tests the BigDecimal comparison operators %includes: #include #include %global: using namespace omnetpp::common; static void compare(const char *x, const char *y) { EV << x << "," << y; EV << ": "; try { BigDecimal xx = BigDecimal::parse(x); BigDecimal yy = BigDecimal::parse(y); if (xx < yy) EV << "< "; if (xx <= yy) EV << "<= "; if (xx == yy) EV << "== "; if (xx >= yy) EV << ">= "; if (xx > yy) EV << "> "; EV << "\n"; } catch (std::exception& e) { EV << "ERROR: " << e.what() << "\n"; } } %activity: #define T(x,y) compare(#x, #y); EV << "\n"; // < T(0,0.000000000000000001); T(-0.000000000000000001,0); T(-123456789012345678,0); T(0,123456789012345678); T(0.123456789012345678, 0.123456789012345679); T(0.99999999999999999, 1); T(0.99999999999999999, 123456789012345678); T(-1, -0.999999999999999999); T(0.123456789012345679,0.12345678912345678); T(90.210190538889,785.4248266628098885) T(123456789012345678,+Inf); T(-Inf,-1234567890123456789); T(-Inf,+Inf) // == T(0,0); T(123456789012345678,123456789012345678) T(-123456789012345678,-123456789012345678) T(0.000000000000000001, 0.000000000000000001) T(-Inf,-Inf); T(+Inf,+Inf); // > T(0.000000000000000001,0); T(0,-0.000000000000000001); T(0,-123456789012345678); T(123456789012345678,0); T(0.123456789012345679,0.123456789012345678); T(1,0.99999999999999999); T(123456789012345678,0.99999999999999999); T(-0.999999999999999999,-1); T(9.01,9); T(+Inf,123456789012345678); T(-1234567890123456789,-Inf); T(+Inf,-Inf) // NaN T(NaN,0); T(0,NaN); T(NaN,NaN); EV << ".\n"; %contains: stdout 0,0.000000000000000001: < <= -0.000000000000000001,0: < <= -123456789012345678,0: < <= 0,123456789012345678: < <= 0.123456789012345678,0.123456789012345679: < <= 0.99999999999999999,1: < <= 0.99999999999999999,123456789012345678: < <= -1,-0.999999999999999999: < <= 0.123456789012345679,0.12345678912345678: < <= 90.210190538889,785.4248266628098885: < <= 123456789012345678,+Inf: < <= -Inf,-1234567890123456789: < <= -Inf,+Inf: < <= 0,0: <= == >= 123456789012345678,123456789012345678: <= == >= -123456789012345678,-123456789012345678: <= == >= 0.000000000000000001,0.000000000000000001: <= == >= -Inf,-Inf: <= == >= +Inf,+Inf: <= == >= 0.000000000000000001,0: >= > 0,-0.000000000000000001: >= > 0,-123456789012345678: >= > 123456789012345678,0: >= > 0.123456789012345679,0.123456789012345678: >= > 1,0.99999999999999999: >= > 123456789012345678,0.99999999999999999: >= > -0.999999999999999999,-1: >= > 9.01,9: >= > +Inf,123456789012345678: >= > -1234567890123456789,-Inf: >= > +Inf,-Inf: >= > NaN,0: 0,NaN: NaN,NaN: .