Re: Spaceship and NaNs

From: Date: Mon, 15 Jun 2015 19:55:04 +0000
Subject: Re: Spaceship and NaNs
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-86672@lists.php.net to get a copy of this message
As far as I know, we made it that way in order to enforce an int return type all the time. int(-1) is indeed the sensible value for this. (Mainly int(0) does not work because it'd mean equality and so we're left with int(-1) and int(1).) Just because other comparison ops already return a bool, we can return bool(false) there. Bob > Am 15.06.2015 um 21:44 schrieb Dmitry Stogov <dmitry@zend.com>: > > Hi, > > I found a problem with spaceship operator. > It doesn't define result for comparison with NaN. > > $ sapi/cli/php -r 'var_dump(sqrt(-1) <=> 0);' > int(-1) > $ sapi/cli/php -r 'var_dump(0 <=> sqrt(-1));' > int(-1) > > $ sapi/cli/php -r 'var_dump(0 < sqrt(-1));' > bool(false) > > all other comparison operators return "false" as well. > > Thanks. Dmitry.

« previous php.internals (#86672) next »