Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121153 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59244 invoked from network); 27 Sep 2023 13:38:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Sep 2023 13:38:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C2291804B0 for ; Wed, 27 Sep 2023 06:38:18 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS30827 82.113.144.0/20 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Wed, 27 Sep 2023 06:38:17 -0700 (PDT) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 5AF4D10C4D1; Wed, 27 Sep 2023 14:38:17 +0100 (BST) Date: Wed, 27 Sep 2023 14:38:16 +0100 (BST) To: Larry Garfield cc: php internals In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV] [RFC] [Discussion] Rounding Integers as int From: derick@php.net (Derick Rethans) On Tue, 26 Sep 2023, Larry Garfield wrote: > ceil and floor should > always return ints, unconditionally, because that's literally what > their purpose is. But that RFC doesn't say that, which makes me quite > confused. They can't do that. ceil(2.4e102) can't be repesented as an integer. > Similarly, the BC shim would therefore be (float)ceil($x), not > ceil((float)$x), which... I don't think that would even do anything, > would it? (float) $int *could* also do something: $ php -dprecision=20 -r 'echo (float) 1152921504606846974;' 1152921504606846976 $ php -dprecision=20 -r 'var_dump(ceil((float) 1152921504606846974));' double(1152921504606846976) (see how the 74 changes into 76 at the end). Integers in the ranges LONG_MAX to 2^53, and -2^53 to LONG_MIN can't be represented as whole numbers as float, and some precision is lost. cheers, Derick