I think we don't understand each other.
I never said that Locale_Math is a 100% clone of BCMath.
And I noted that there IS a limitation on this approach.
It is even documented in the manual.
And the limitation fits the needs of the components which make use of it.
When this is not the case for your application you are still free to use
whatever you need.
I did not want to offend you ;-)
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message -----
From: "zelnaga" <[email protected]>
To: <[email protected]>
Sent: Wednesday, February 25, 2009 11:13 PM
Subject: Re: [fw-general] pure-PHP BigInteger support
I think you've misunderstood my post, so I'll start again.
From Zend_Locale_Math_PhpMath::Pow():
$result = pow($op1, $op2);
pow() is a function built into PHP. It does not work on "BigIntegers" of
infinite precision. This is in contrast to bcmath.
A demonstration:
<?php
require_once 'Zend/Locale/Math.php';
require_once 'Zend/Locale/Math/PhpMath.php';
Zend_Locale_Math_PhpMath::disable();
$a = Zend_Locale_Math::Pow('2', '128');
$b = Zend_Locale_Math_PhpMath::Pow('2', '128');
var_dump($a);
echo "\r\n<br />\r\n";
var_dump($b);
?>
What do you get as the output? Here's what I get:
string(39) "340282366920938463463374607431768211456"
string(19) "3.4028236692094E+38"
Those are very definitely not equal. Tell me - how do you propose
inferring
the least significant digit from $b? It can be determined from $a by
doing
$a[strlen($a) - 1]. What are you going to do for $b?
The fact is that when bcmath is unavailable, Zend_Locale_Math does *not*
behave identically to how it does when bcmath is available. To say the
fallback solution behaves identically to the normal behavior is, frankly,
incorrect.
Here's the original BigInteger library I linked to:
http://phpseclib.cvs.sourceforge.net/viewvc/*checkout*/phpseclib/phpseclib/Math/BigInteger.php?revision=1.5
That gives you the *same* result when gmp is available, when bcmath is
available, and when neither are available. That's the behavior I would
expect from a BigInteger class that presumes to have a PHP fallback
solution
- not this "we'll give you completely different output" approach that is
being taken with Zend.
thomasW wrote:
See my notes below
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
----- Original Message -----
From: "zelnaga" <[email protected]>
To: <[email protected]>
Sent: Wednesday, February 25, 2009 9:37 PM
Subject: Re: [fw-general] pure-PHP BigInteger support
thomasW wrote:
There is already a pure PHP solution within ZF which can be used.
Zend_Locale_Math is a bcmath clone which does automatically use BCMath
and
when it's not available switch to pure PHP implementation. For examples
on
usage look at Zend_Locale_Format or Zend_Measure_Abstract.
http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Locale/Math/PhpMath.php
Interesting. Correct me if I'm wrong, but it appears to me that when
bcmath
is unavailable that library ceases to be a multiple precision integer
arithmetic library (ie. BigInteger) and instead supports regular old
32-bit
integers (or 64-bit for 64-bit machines)?
No, it does not limit to 32 bit integer. Still there is a sort of
limitation
which is related to the usecase this lib was created for.
If so, I'm not even sure it'd be
accurate to say that it "falls back" on anything - if bcmath is
unavailable
its feature set becomes completely different.
No it does not.
If you absolutely need
128-bit integers and bcmath is unavailable that library isn't going to
be
sufficient
We're calculating dates with a unixtimestamp from BC (-4000) which
extends
32bit with ease.
and if you have bcmath and can live with 32-bit integers that
library is probably going to slow things down for you
Why should it ?
When BCMath is available you will get the result from BCMath and not the
lib.
(bcadd(), I suspect, can't compare in speed to the + operator).
You have to decide if you are in need of BCMath or of PHP limited
integer.
This is a design decision and not a fault or problem of a class.
You are ALWAYS slower when you have to use a component or extension than
using PHP native "+" notation.
If that library actually does support integers of any length regardless
of
whether or not bcmath is installed then shouldn't that library - and not
Zend_Crypt_Math_BigInteger - be used by Zend_Crypt_DiffieHellman?
Can't say anything about that. Zend_Crypt is no longer developed by it's
maintainer and unchanged in incubator since mid 2008.
So I expect that this component is dead.
--
View this message in context:
http://www.nabble.com/pure-PHP-BigInteger-support-tp22068811p22211234.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
View this message in context:
http://www.nabble.com/pure-PHP-BigInteger-support-tp22068811p22213096.html
Sent from the Zend Framework mailing list archive at Nabble.com.