Concept is simple.
Need, remove GMPInt, leave only GMPFloat.
For backward compatibility in php.ini set default values
gmp.default_precision = 0
Anyone who wants to work with float, must specify precision > 0
What do you think about this?
For backward compatibility in php.ini set default values
gmp.default_precision = 0
No. INI setting is not backwards compatibility. An ini setting means
that everybody has to care about it and mind it and either check or
set it.
An alternative is a runtime setting (gmp_set_compatiility(true) ), in
case the change is really important. I haven't looked further but
behavior should not depend on ini. We made the mistake and should learn
not repeat.
johannes
Ok, add precision param to gmp_init.
gmp_init ( mixed $number [, int $base = 0 ], int $precision = 0]] )
$a = gmp_init (3); // type float, by precision = 0
$b = gmp_init (3.333, 10, 3); // float
$c = $a + $b; // float
2014-04-22 0:07 GMT+03:00 Johannes Schlüter johannes@schlueters.de:
For backward compatibility in php.ini set default values
gmp.default_precision = 0No. INI setting is not backwards compatibility. An ini setting means
that everybody has to care about it and mind it and either check or
set it.An alternative is a runtime setting (gmp_set_compatiility(true) ), in
case the change is really important. I haven't looked further but
behavior should not depend on ini. We made the mistake and should learn
not repeat.johannes
On Mon, Apr 21, 2014 at 10:40 PM, Park Framework
park.framework@gmail.comwrote:
Concept is simple.
Need, remove GMPInt, leave only GMPFloat.
For backward compatibility in php.ini set default values
gmp.default_precision = 0
Anyone who wants to work with float, must specify precision > 0
What do you think about this?
This is not possible, because GMP integers and GMP floats are fundamentally
and inherently different types.
A GMP integer isn't just a GMP float with zero precision. Actually, what I
think you're missing here is that the GMP floating point type is just that:
A floating point type. This means that it is not precise. What you
specify as the GMP float precision actually translates to the size of the
mantissa/significand, not the number of places after the comma.
GMP integers on the other hand are precises. Furthermore a primary
application for GMP integers are computations over cyclic groups, as well
as other number theoretic computations. The operations for these are not a
available for the floating point type (and frankly, wouldn't really make
sense).
Maybe you're looking for the BCMath extension?
Nikita
Yes, now I understand better the sense in GMPInt, you are right that there
should be different classes.
We use BCMath, but bulky code BCMath:
bcmul(bcadd($a, $b, $scale), 2, $scale)
I want to write simple:
$a + $b * 2
I'm looking forward to implementing GMPFloat
2014-04-24 11:17 GMT+03:00 Nikita Popov nikita.ppv@gmail.com:
On Mon, Apr 21, 2014 at 10:40 PM, Park Framework <park.framework@gmail.com
wrote:
Concept is simple.
Need, remove GMPInt, leave only GMPFloat.
For backward compatibility in php.ini set default values
gmp.default_precision = 0
Anyone who wants to work with float, must specify precision > 0
What do you think about this?This is not possible, because GMP integers and GMP floats are
fundamentally and inherently different types.A GMP integer isn't just a GMP float with zero precision. Actually, what I
think you're missing here is that the GMP floating point type is just that:
A floating point type. This means that it is not precise. What you
specify as the GMP float precision actually translates to the size of the
mantissa/significand, not the number of places after the comma.GMP integers on the other hand are precises. Furthermore a primary
application for GMP integers are computations over cyclic groups, as well
as other number theoretic computations. The operations for these are not a
available for the floating point type (and frankly, wouldn't really make
sense).Maybe you're looking for the BCMath extension?
Nikita
Hi!
We use BCMath, but bulky code BCMath:
bcmul(bcadd($a, $b, $scale), 2, $scale)
I want to write simple:
$a + $b * 2I'm looking forward to implementing GMPFloat
Nothing prevents one from doing with bcmath what was done with GMP with
regard to move to objects and support for operators, as far as I can see.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
How to make PHP userland class, overloading math operators?
2014-04-24 23:29 GMT+03:00 Stas Malyshev smalyshev@sugarcrm.com:
Hi!
We use BCMath, but bulky code BCMath:
bcmul(bcadd($a, $b, $scale), 2, $scale)
I want to write simple:
$a + $b * 2I'm looking forward to implementing GMPFloat
Nothing prevents one from doing with bcmath what was done with GMP with
regard to move to objects and support for operators, as far as I can see.--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
How to make PHP userland class, overloading math operators?
From userland it is impossible, this is why I was talking about what was
done in GMP - converting extension to support operators, on extension
level.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Yes agree, it the right thing.
In many business calculations implemented pattern Money.
If there is a class BCMath or GMPFloat which it is possible to extend,
wherein overload operators, will interesting solutions.
<?php
class Money extends BCMath
{
protected $rate;
protected $amount;
protected $currency;
//....
}
?>
2014-04-25 0:33 GMT+03:00 Stas Malyshev smalyshev@sugarcrm.com:
Hi!
How to make PHP userland class, overloading math operators?
From userland it is impossible, this is why I was talking about what was
done in GMP - converting extension to support operators, on extension
level.--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227