Re: [RFC] Floating Point support in GMP extension
| From: | Sara Golemon | Date: | Sun, 05 Jan 2014 17:23:54 +0000 |
| Subject: | Re: [RFC] Floating Point support in GMP extension | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-71008@lists.php.net to get a copy of this message | ||
On Sat, Jan 4, 2014 at 11:45 PM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:
> I have a question here: why we must keep gmp integers and gmp floats
> within the same object? They have different types in GMP library, PHP
> has different types for ints and floats, internally in PHP they would be
> using different code and different structures, API would be different -
> why have the same object at all?
>
I considered that approach too (and even had it in my initial draft as
"proposal#2"), but what I ended up putting into the RFC felt more
"PHP" to me (in that we're dealing with a number, not an int versus a
float necessarily). I'm totes not averse to having GMPInt and
GMPFloat (descended from abstract GMPNumber); After all, that's what
the discussion period is for.
> Also, I'm not sure how exactly "all other gmp_*() functions" are
> supposed to work on floats - for many of them it just make no sense
> (such as factorial or q/r division or modulo), for others like bit
> functions it technically could make sense but would probably be not
> useful since nobody does bit ops on floats... Maybe it would make more
> sense to look into what GMP library does with floats and write different
> function set from there?
>
On a case by case basis. As you say, some of those cases will be
"throw an error on trying to use a float", and some functions would be
new.
For common stuff though, like gmp_add(), I think it'd be silly to have
gmp_add() + gmp_float_add() as separate APIs, especially since one
would have to be smart enough to handle Int+Float mixing anyway. ((Or
you'd have to perform explicit casts, e.g.: $three = gmp_add(
gmp_init("1") + gmp_int(gmp_float_init("2.0")) );
-Sara