%description: Test the integer exponentiation operator in NED expressions (they are implemented with cDynamicExpression). 64-bit signed arithmetic. %global: void test(const char *expr) { cDynamicExpression e; e.parse(expr); std::string result; try { cNedValue v = e.evaluate(); result = v.str(); } catch (std::exception& e) { result = e.what(); } EV << expr << " ==> " << result << "\n"; } void test(const char *s1, const std::string& s2, const char *s3) { test((std::string(s1) + " " + s2 + " " + s3).c_str()); } %activity: test("2^0"); test("2^1"); test("2^2"); test("2^3"); test("2^4"); test("2^5"); test("2^6"); test("2^7"); test("2^8"); test("2^9"); test("2^10"); test("2^15"); test("2^16"); test("2^31"); test("2^32"); test("2^60"); test("2^61"); test("2^62"); test("2^63"); // negative exponent test("2^-1"); test("2^-2"); // negative base test("-2^0"); test("-2^1"); test("-2^2"); test("-2^3"); test("-2^63"); test("-2^64"); EV << ".\n"; %contains: stdout 2^0 ==> 1 2^1 ==> 2 2^2 ==> 4 2^3 ==> 8 2^4 ==> 16 2^5 ==> 32 2^6 ==> 64 2^7 ==> 128 2^8 ==> 256 2^9 ==> 512 2^10 ==> 1024 2^15 ==> 32768 2^16 ==> 65536 2^31 ==> 2147483648 2^32 ==> 4294967296 2^60 ==> 1152921504606846976 2^61 ==> 2305843009213693952 2^62 ==> 4611686018427387904 2^63 ==> operator "^": Overflow during integer exponentiation, try casting operands to double 2^-1 ==> operator "^": Negative exponent in integer exponentiation, cast operands to double to allow it 2^-2 ==> operator "^": Negative exponent in integer exponentiation, cast operands to double to allow it -2^0 ==> 1 -2^1 ==> -2 -2^2 ==> 4 -2^3 ==> -8 -2^63 ==> -9223372036854775808 -2^64 ==> operator "^": Overflow during integer exponentiation, try casting operands to double .