Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70914 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95051 invoked from network); 30 Dec 2013 06:42:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Dec 2013 06:42:13 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.53 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.53 mail-vb0-f53.google.com Received: from [209.85.212.53] ([209.85.212.53:40241] helo=mail-vb0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/51-20534-4C511C25 for ; Mon, 30 Dec 2013 01:42:12 -0500 Received: by mail-vb0-f53.google.com with SMTP id o19so5555390vbm.40 for ; Sun, 29 Dec 2013 22:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MH2O3CfGIOsFOzE8u1O5c8IJLQ8L54z0avvX/cVS4QU=; b=gZ51VmzRTqzy2QHtWaueLVO6LwbRvAeg61/nYJP5I7V/pQ/PIgBeQv7VgOf/1JPi4M u7O/asBdTOkgDscBxnsxuTdhd2tCtIM+rA0FFAnylRO8qWk6OKBnP3mlzH4dh8D009Tx a6JN2iDmxhPztDsn6WGWvh5dlkE8PZLbvLxkFcXARvT8RuV4pB0j5rLCaxe2xnauZb6g kfqtqKQHkNQ+7ahgS7lPqf/v58Wumh9F4cRBN+DUNTUeMJ69OARfXicynBBggPM5IGBP BcbkoHw+xl/i8Iloqoc9SkGtqYmh+ovpAnHHX2nn6KFJLtl7lORjdSUlSVHNpg3DREVK O83A== MIME-Version: 1.0 X-Received: by 10.59.8.100 with SMTP id dj4mr583585ved.55.1388385730071; Sun, 29 Dec 2013 22:42:10 -0800 (PST) Received: by 10.58.128.33 with HTTP; Sun, 29 Dec 2013 22:42:09 -0800 (PST) In-Reply-To: References: Date: Mon, 30 Dec 2013 14:42:09 +0800 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7bf0d6c240bfec04eebabe66 Subject: Re: [PHP-DEV] Re: GMP and empty() From: tjerk.meesters@gmail.com (Tjerk Meesters) --047d7bf0d6c240bfec04eebabe66 Content-Type: text/plain; charset=ISO-8859-1 Hi, On Mon, Dec 30, 2013 at 12:59 PM, Yasuo Ohgaki 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 --047d7bf0d6c240bfec04eebabe66--