Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91171 invoked from network); 15 Jun 2015 20:44:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jun 2015 20:44:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.170 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.170 mail-pd0-f170.google.com Received: from [209.85.192.170] ([209.85.192.170:36671] helo=mail-pd0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/D1-15639-0493F755 for ; Mon, 15 Jun 2015 16:44:49 -0400 Received: by pdjm12 with SMTP id m12so80500571pdj.3 for ; Mon, 15 Jun 2015 13:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=nQ2V0IWfsBX9KJ9j6HlmhD5XQjqVvh9wEUD3FLNwTRk=; b=mC/59lbl5+cwxUqIVGyVBBFXFJ1wbwrZhed7ZMfUzAlKv+YtAxGqlkOMoA7GhEWOxn rxNkh0549JC1byR9smmSt3UGIRBRQNqMRTe4Sv/uLxXIwozrN5TTYJsHXAj2wnFZfs2j YlBJ+6NgUM61344zhdr/UgcqLfRwWKcfrW7mQe39vEHnhyobWe8ByOHRLOZOEYMtQV6i mm8yttMsKNEvBkX35/5pw8dX3lnbEjCmmOo3npO/bh1pHLVuivwpEDAustrMerP2c2ku 38hiXmxMCIjooa6aHzWcGkSHJwUO2r7GF+X7dOlBaBF2GQP1dL7WQF50wBwyoCyrbLCP Dpwg== X-Received: by 10.66.218.6 with SMTP id pc6mr51375407pac.20.1434401085749; Mon, 15 Jun 2015 13:44:45 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id fp3sm13143168pdb.52.2015.06.15.13.44.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 13:44:44 -0700 (PDT) Message-ID: <557F392C.6000907@gmail.com> Date: Mon, 15 Jun 2015 13:44:28 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Dmitry Stogov , davey@php.net, Andrea Faulds , Anatol Belski , Kalle Sommer Nielsen , PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: Spaceship and NaNs From: smalyshev@gmail.com (Stanislav Malyshev) 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. I think <=> is defined as: 1. if < returns true, then negative 2. if == returns true, then 0 3. otherwise, positive https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#relational-operators So the result here is wrong I assume. I suspect this is the consequence of how compare_function treats IS_DOUBLE - it first subtracts them (which produces NaN) and then does ZEND_NORMALIZE_BOOL - which is: #define ZEND_NORMALIZE_BOOL(n) \ ((n) ? (((n)>0) ? 1 : -1) : 0) Since NaN > 0 is false, what we get is -1. I guess we should add check for NaN in either ZEND_NORMALIZE_BOOL or comparison routine, but not sure what comparing to NaN should produce... Always false? AFAIK NaN is not equal to NaN so that may be the best option. The individual comparison operators already return false with NaN but I suspect not for the right reasons... -- Stas Malyshev smalyshev@gmail.com