我感到困惑的是,我如何通过PHPUnit来增加数量.
我写了斐波那契数.但是如果是100,我在下面写道.
http://github.com/sanemat/kata-fibonacci-phpunit/commit/b6b2945d2eff1b95e7e25b8be8c7bff11098d44d
我希望此返回TRUE.
失败了
http://www.php.net/manual/en/language.types.float.php
我明白“永远不要为了平等而比较”.那么如何放大呢?
最后,我将to_string彼此进行比较.
如何在PHP中比较大数?
http://github.com/sanemat/kata-fibonacci-phpunit/commit/70a0e47bc0737be47da8fe8726634edd851d940d
我闻起来像难闻的气味.但是我不知道更好的方法.
请告诉我您如何主张它?
====
php > $a = 354224848179261915075;
php > echo $a;
3.5422484817926E+20
php > $b = 3.5422484817926E+20;
php > echo $b;
3.5422484817926E+20
php > echo ($a == $b) ? 'TRUE' : 'FALSE';
FALSE
php > echo gmp_cmp($a, $b);
PHP Warning: gmp_cmp(): Unable to convert variable to GMP - wrong type in php shell code on line 1
php > echo (strval($a) == strval($b)) ? 'TRUE' : 'FALSE';
TRUE
====
environment
$uname -a
Linux localhost.localdomain 2.6.33.6-147.2.4.fc13.x86_64 #1 SMP Fri Jul 23 17:14:44 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
$php --version
PHP 5.3.3 (cli) (built: Jul 22 2010 15:57:00)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
解决方法:
要处理大量数字,有BCMath libray的PHP.