%description: Tests the BigDecimal::BigDecimal(double) method %includes: #include #include #include %global: using namespace omnetpp::common; static double zero = 0.0; static void convertAndPrint(double d) { try { BigDecimal bd(d); EV << bd.str() << ", intVal=" << bd.getIntValue() << ", scale=" << bd.getScale() <<"\n"; } catch (std::exception& e) { EV << "ERROR: " << e.what() << "\n"; } } %activity: #define T(x) EV << #x << " ==> "; convertAndPrint(x) EV << "\n"; // positive cases T(0.0); T(1.0); T(-1.0); T(1234567890123456.0); T(1234567890123.456); T(1234567890.123456); T(123456.7890123456); T(123.4567890123456); T(0.1234567890123456); T(-1234567890123456.0); T(zero/zero); T(1/zero); T(-1/zero); // negative cases T(12345678901234567890.0); // overflow EV << ".\n"; %contains: stdout 0.0 ==> 0, intVal=0, scale=0 1.0 ==> 1, intVal=1, scale=0 -1.0 ==> -1, intVal=-1, scale=0 1234567890123456.0 ==> 1234567890123456, intVal=1234567890123456, scale=0 1234567890123.456 ==> 1234567890123.456053, intVal=1234567890123456053, scale=-6 1234567890.123456 ==> 1234567890.123456, intVal=1234567890123456, scale=-6 123456.7890123456 ==> 123456.7890123456015, intVal=1234567890123456015, scale=-13 123.4567890123456 ==> 123.4567890123455806, intVal=1234567890123455806, scale=-16 0.1234567890123456 ==> 0.123456789012345579, intVal=123456789012345579, scale=-18 -1234567890123456.0 ==> -1234567890123456, intVal=-1234567890123456, scale=0 zero/zero ==> NaN, intVal=0, scale=2147483647 1/zero ==> +Inf, intVal=1, scale=2147483647 -1/zero ==> -Inf, intVal=-1, scale=2147483647 12345678901234567890.0 ==> ERROR: BigDecimal: normalize(): Arithmetic overflow .