Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96439 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48237 invoked from network); 18 Oct 2016 18:46:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Oct 2016 18:46:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain belski.net from 85.214.73.107 cause and error) X-PHP-List-Original-Sender: anatol.php@belski.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:42240] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/C1-40890-E0E66085 for ; Tue, 18 Oct 2016 14:46:39 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 58F8F784A04; Tue, 18 Oct 2016 20:46:35 +0200 (CEST) Received: from w530phpdev (p57A878CB.dip0.t-ipconnect.de [87.168.120.203]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h1123647.serverkompetenz.net (Postfix) with ESMTPSA id 245817849E5; Tue, 18 Oct 2016 20:46:33 +0200 (CEST) To: "'PHP Internals'" Cc: "'Davey Shafik'" , "'Joe Watkins'" Date: Tue, 18 Oct 2016 20:46:28 +0200 Message-ID: <073601d2296f$f27135e0$d753a1a0$@belski.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdIpZYnqPN74wDpmQ5SYtCAmxYoAuQ== Content-Language: en-us Subject: Constants for better double edge case handling From: anatol.php@belski.net ("Anatol Belski") Hi, I would like to suggest adding the following constants REGISTER_MAIN_LONG_CONSTANT("PHP_DBL_DIG", DBL_DIG, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_DOUBLE_CONSTANT("PHP_DBL_MAX", DBL_MAX, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_DOUBLE_CONSTANT("PHP_DBL_MIN", DBL_MIN, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_DOUBLE_CONSTANT("PHP_DBL_EPSILON", DBL_EPSILON, CONST_PERSISTENT | CONST_CS); The goal of this is to improve the handling of double in the user land. Here are a couple of usages to illustrate the idea. The comparison of double values. $d0 = sin(M_PI/6.0); $d1 = .5; var_dump( $d0, $d1, abs($d0 - $d1), $d0 == $d1, abs($d0 - $d1) < PHP_DBL_EPSILON ); float(0.5) float(0.5) float(5.5511151231258E-17) bool(false) bool(true) The rounding behavior, max possible value representable by the string conversion. $d = .2345234523453245324323465; echo $d, " ", round($d, 20), " ", round($d, PHP_DBL_DIG); 0.23452345234532 0.23452345234532 0.23452345234533 Producing INF. There's currently no explicit way to produce INF and NAN, whereby NAN is gettable with sqrt(-1). echo PHP_DBL_MAX*PHP_DBL_MAX, " ", -PHP_DBL_MAX*PHP_DBL_MAX; INF -INF In general, it is more about the possibility to handle the edge cases properly. While such cases would cause unnecessary overhead and likely a BC breach with a direct core implementation, they'd be fine to handle in the scripts where it comes to it. I think, at least DBL_DIG and DBL_EPSILON should be mapped to the constants, to provide a base for more flexibility. The change itself is pretty outspoken, so I'm not sure it requires an RFC. I would target at least master with this. Or 7.1, if RMs are ok. Regards Anatol