$n = 2; 10-$n = 87
好吧,这就是我正在做的:
$total = (array_sum($odds))+$evens;
$total = str_split($total);
echo 'total[1]: '.$total[1].'<br />';
echo '10-$total[1]: ' . (10-($total[1]));
输出是:
total[1]: 2
10-$total[1]: 87
我的猜测是它被视为字符串,但我该如何修复它?
所以,我想知道的是
wh 做什么 (10-($total[1])); = 87?
Update:
yeah my mistake, a phantom 7,
but can anyone now tell me why:
echo $flybuys.' % '.$check.'<br />';
$res = $flybuys % $check;
echo 'res: '.$res;
输出: 6014359000000928 % 8 分辨率:7
well this is what i am doing:
$total = (array_sum($odds))+$evens;
$total = str_split($total);
echo 'total[1]: '.$total[1].'<br />';
echo '10-$total[1]: ' . (10-($total[1]));
and the output is:
total[1]: 2
10-$total[1]: 87
my guess is it is being treated as a string, but how do i fix it?
so, what i want to know is
wh does (10-($total[1])); = 87?
Update:
yeah my mistake, a phantom 7,
but can anyone now tell me why:
echo $flybuys.' % '.$check.'<br />';
$res = $flybuys % $check;
echo 'res: '.$res;
outputs:
6014359000000928 % 8
res: 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
模数结果不准确是因为 6014359000000928 (~2^52) 超出了 int 的范围,因此 PHP 将其解释为浮点数。这意味着您拥有 32 位系统(PHP 数据类型大小因体系结构而异)。如果您需要对大数进行数学运算,可以使用 GMP。例如:
确保将大量数字作为字符串传递给 GMP。
The inaccurate modulus result is because 6014359000000928 (~2^52) is beyond the bounds of an int, so PHP interprets it as a float. That implies you have a 32-bit system (PHP data type sizes vary depending on architecture). If you need to do math on large numbers, you can use a library like GMP. E.g.:
Make sure you pass large numbers to GMP as strings.
如果它被识别为字符串,您可以尝试使用将其转换为 int
说实话,您可以在进行字符串拆分时将 $total 数组转换为 int:
表示数字的字符串也可以转换为 ( float),并取决于您拥有的 php 版本(双精度)。
If it is getting recognized as a string you could try casting it to an int using
To be honest, you could probably cast the $total array into an int right when you do the string split:
Strings that represent numbers can also be cast into (float), and depending on which version of php you have (double).
无法重现此问题:
绝对是预期的行为......
Couldn't reproduce this issue:
Absolutely the expected behavior...
我添加这个作为答案是因为评论中没有足够的空间:
如果这是描述的算法的实现 这里我真的认为模检查
6014359000000928 % 8 == 0
不应该在那里。例如,考虑前 15 位数字,如下所示:
6014 3590 0000 062
。对于偶数
为15,奇数
为24,总
为39,检查
为1。任何数字模1是 0。因此,6014 3590 0000 0628
的有效值为6014 3590 0000 0620
或6014 3590 0000 0627
。这没有道理。我认为您必须使用
check
检查最后一位数字是否相等。在这种情况下,只有6014 3590 0000 0621
有效。I added this as an answer because in a comment is not enough space:
If this is the implementation of the algorithm described here i really think that modulo check
6014359000000928 % 8 == 0
shouldn't be there.For example consider the number with the first 15 digits like that:
6014 3590 0000 062
. For thatevens
is 15,odds
is 24,total
is 39 andcheck
is 1. Any number modulo 1 is 0. So6014 3590 0000 0628
is valid as6014 3590 0000 0620
is or6014 3590 0000 0627
. That doesn't make sense.I think you have to check the last digit for equality with
check
. In that case only6014 3590 0000 0621
would be valid.