Re: Re: GMP and empty()
| From: | Tjerk Meesters | Date: | Mon, 30 Dec 2013 06:42:09 +0000 |
| Subject: | Re: Re: GMP and empty() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70914@lists.php.net to get a copy of this message | ||
Hi,
On Mon, Dec 30, 2013 at 12:59 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> Hi all,
>
> I thought GMP object does not work with math functions, but some of them
> work.
> Apparently, I was only testing with function that does not work with GMP.
> Some math function
> works. e.g. pow() with small value. min()/max() seems ok.
>
> Not only empty(), but there are number of wired behavior with GMP and
> functions.
>
> I haven't tried them all, but we need to work more for these.
> It seems time to write more tests and fix issues.
>
> === pow() ===
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("2"); var_dump(pow($v, 10));'
> int(1024)
>
> This works fine.
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("223423"); var_dump(pow($v, 234242));'
> float(INF)
>
> This returns float(INF). It may be acceptable. Returning GMP object with
> correct value is better.
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("223423423423423423423422342342342342.234234234");
> var_dump(pow($v, 234242));'
> int(0)
>
> but this returns int(0).
> === round()/floor()/ceil()===
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("25.234242342"); var_dump(round($v));'
> float(0)
>
> It should be 25. floor()/ceil() is the same.
>
> ===abs()===
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("25.234242342"); var_dump(abs($v));'
> int(0)
>
> It returns int(0).
>
>
> ===acos()===
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("25.234242342"); var_dump(acos($v), acos(25.234242342));'
> float(1.5707963267949)
> float(NAN)
>
> Something wrong.
>
> ===cos()===
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("25.234242342"); var_dump(cos($v), cos(25.234242342));'
> float(1)
> float(0.99485318302495)
>
> Almost correct, but it's not.
>
This is because gmp_init() yields bool(false) if you pass a floating point
value, as it should because it's meant for arbitrary-length **integers** ;-)
>
> If GMP integer is passed, it raises E_WARNING.
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("2"); var_dump(cos($v), cos(2));'
> Warning: cos() expects parameter 1 to be double, object given in Command
> line code on line 1
> NULL
> float(-0.41614683654714)
>
> ===log===
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("2"); var_dump(log($v), log(2));'
> Warning: log() expects parameter 1 to be double, object given in Command
> line code on line 1
> NULL
> float(0.69314718055995)
>
> [yohgaki@dev php-src]$ ./php-bin -d error_reporting=-1 -r '$v =
> gmp_init("2.2"); var_dump(log($v), log(2.2));'
> float(-INF)
> float(0.78845736036427)
>
>
> Something wrong.
>
You could argue that it would make sense to cast GMP to a native integer or
float type, but it will most likely lose precision; otherwise, what would
be the point of using GMP in the first place?
>
>
--
--
Tjerk