diff --git a/cal/regress.cal b/cal/regress.cal index c6501b6..c083e0c 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -305,6 +305,8 @@ print '008: parsed test_variables()'; */ define test_arithmetic() { + local x; + print '400: Beginning test_arithmetic'; vrfy(3+4==7, '401: 3 + 4 == 7'); @@ -366,8 +368,18 @@ define test_arithmetic() vrfy((2^23209-1)^(2-2) == 1, '457: (2^23209-1)^(2-2) == 1'); vrfy((2^23209-1)^((2^23209-1)-(2^23209-1)) == 1, '458: (2^23209-1)^((2^23209-1)-(2^23209-1)) == 1'); + vrfy(0^2 == 0, '459: 0^2 == 0'); + vrfy(0^3 == 0, '460: 0^3 == 0'); + vrfy(0^12 == 0, '461: 0^12 == 0'); + vrfy(0^13 == 0, '462: 0^13 == 0'); + x = 0; + vrfy(x == 0, '463: x == 0'); + vrfy(0^2 == 0, '464: 0^2 == 0'); + vrfy(0^3 == 0, '465: 0^3 == 0'); + vrfy(0^12 == 0, '466: 0^12 == 0'); + vrfy(x^13 == 0, '467: x^13 == 0'); - print '459: Ending test_arithmetic'; + print '462: Ending test_arithmetic'; } print '009: parsed test_arithmetic()'; diff --git a/cal/test8900.cal b/cal/test8900.cal index 5e2b10c..6a237fb 100644 --- a/cal/test8900.cal +++ b/cal/test8900.cal @@ -2058,11 +2058,17 @@ define t010() return 5; } /* - * Once, when an expression such as 0^(6-6) returned 0, + * When an expression such as 0^(6-6) returned 0, * then stirling2(10, 5) == 42525. However when we made9 - * 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120. + * 0^(6-6) == 0^0 == 1, then stirling2(10, 5) == 5102999/120 + * as in: + * + * if ((stirling2(10, 5) - (5102999/120)) != 0) { + * epsilon(eps); + * return 6; + * } */ - if ((stirling2(10, 5) - (5102999/120)) != 0) { + if ((stirling2(10, 5) - 42525) != 0) { epsilon(eps); return 6; } diff --git a/value.c b/value.c index 4f5fb38..8981b81 100644 --- a/value.c +++ b/value.c @@ -1884,9 +1884,14 @@ powvalue(VALUE *v1, VALUE *v2, VALUE *vres) *vres = error_value(E_1OVER0); break; } - /* 0 ^ non-neg is 1, including 0^0 */ vres->v_type = V_NUM; - vres->v_num = qlink(&_qone_); + if (qiszero(v2->v_num)) { + /* 0 ^ 0 is 1 */ + vres->v_num = qlink(&_qone_); + } else { + /* 0 ^ (exp>0) is 0 */ + vres->v_num = qlink(&_qzero_); + } } else if (qisint(real_v2)) { vres->v_num = qpowi(v1->v_num, real_v2); } else {