ID: 44995 Updated by: sjo...@php.net Reported By: nat at fishtrap dot co dot uk Status: Open Bug Type: BC math related Operating System: Linux PHP Version: 5.2CVS-2008-05-14 (snap) New Comment:
John Hasler said: The example in #44995 is wrong. "^" has higher precedence than "%" so "4^4%3" means "(4^4)%3" or "256%3", not "4^(4%3). The latter gives a runtime error in bc with scale=1, as it should as fractional exponents are not supported. >From number.c: /* Raise BASE to the EXPO power, reduced modulo MOD. The result is placed in RESULT. If a EXPO is not an integer, only the integer part is used. */ ... ... ... /* Check the base for scale digits. */ if (base->n_scale != 0) bc_rt_warn ("non-zero scale in base"); /* Check the exponent for scale digits. */ if (exponent->n_scale != 0) { bc_rt_warn ("non-zero scale in exponent"); bc_divide (exponent, _one_, &exponent, 0); /*truncate */ } /* Check the modulus for scale digits. */ if (mod->n_scale != 0) bc_rt_warn ("non-zero scale in modulus"); ... ... ... As you can see, non-zero scale is not supported. Thus the bug is in bcpowmod(). It should not accept a scale, and the documentation should say so. Previous Comments: ------------------------------------------------------------------------ [2009-09-19 18:22:41] sjo...@php.net This seems to be a bug in the bc library. I asked jhasler to look into it. ------------------------------------------------------------------------ [2008-05-14 16:26:56] nat at fishtrap dot co dot uk Description: ------------ When using the 4th optional parameter of bcpowmod. The answer is always zero and does not match the answer using bc directly. This is also true if you set the scale using bcscale(1). In short if the scale is non zero I can't find any way of getting anything apart from zero as the result. Reproduce code: --------------- echo bcpowmod("4", "4", "3", 1 ) ,PHP_EOL; Expected result: ---------------- 0.1 in bc scale =1; 4^4%3; .1 Actual result: -------------- 0.0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44995&edit=1