PHP Math: Why is mod (%) not working with fac(13)?
Okay, this one is beyond me: I must be having a long day. Why does (13! mod 10) come out as 4, when the number ends in tw开发者_C百科o 0s??
Try this out:
<?php $thirteen_fac = 6227020800;
echo $thirteen_fac % 10; ?>
Result is 4. Expected 0.
I must be forgetting something exceedingly obvious...
6227020800
is too large for an integer (on a 32 bit system anyway). PHP will store it as float in your variable. The modulo operation will thus use an inexact up/downrounded number as basis.
精彩评论