Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122941 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 2122E1A009C for ; Thu, 4 Apr 2024 20:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712264337; bh=dc2Pt+t23HfX1dICFlI6lVtDol0EpwYmCnkfc9XI6zg=; h=Date:Subject:To:References:From:In-Reply-To:From; b=RakKD6IQ5slZxkomCFzGX/JSmxATbozybqTKt1C1VfPkDacCEOQ7Ii0zbTZDmcrzj HE7hg2v6rtlxGk6/bF8HU1qHme4ym7Uk2vjJXWLPg40ZDIZ9tJxbB2O7X0650CkRqi lIXJ4gQOZfUDIQdpGix+Xp1DLkRhmaRCIZe5uW27z3qTBS+w1Chwk9Ic6MYr/wkBa7 ZDdDCUSOZzVeQeAd1XbrDa7UID+vloU5ovweSDhOUO2rs56CtC60KwbQn2Au/Zi2Bg 15GRi3wDMyKLAWUadlZ4uvT7tQIfJ2hTuWW9Y6gek/LjZVUHaJ9j7m96Oha0h+NJg/ 1GRiHFbxOFelg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4E52180041 for ; Thu, 4 Apr 2024 20:58:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=BAYES_50,DMARC_MISSING, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from gliadin.co.uk (gliadin.co.uk [80.82.115.221]) by php-smtp4.php.net (Postfix) with ESMTP for ; Thu, 4 Apr 2024 20:58:55 +0000 (UTC) Received: from [192.168.0.17] (hari-18-b2-v4wan-169870-cust740.vm1.cable.virginm.net [92.239.242.229]) by gliadin.co.uk (Postfix) with ESMTPSA id BA3FEFA2696 for ; Thu, 4 Apr 2024 23:58:24 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------tE60tlqG61W6NA9qjoAsnWNs" Message-ID: <2c2f2731-acee-4c70-93d9-8ec6d9edc4db@redmagic.org.uk> Date: Thu, 4 Apr 2024 21:58:24 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: internals@lists.php.net References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com> <91111e11ee72ffd18e1a1b2412246d00@gliadin.co.uk> <94B21565-9129-4379-A720-F4EDDD0A8D84@sakiot.com> Content-Language: en-US In-Reply-To: <94B21565-9129-4379-A720-F4EDDD0A8D84@sakiot.com> From: barney@redmagic.org.uk (Barney Laurance) This is a multi-part message in MIME format. --------------tE60tlqG61W6NA9qjoAsnWNs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi again, On 27/03/2024 00:40, Saki Takamachi wrote: >> Do we also need `toFloat` and `toInt` functions? Seems like using explicit functions will be safer than casting. >> >> For toInt I'd expect an exception if the value is outside the range of possible ints. For toFloat it might be nice to have a flag >> argument to give the developer the choice of having it throw if the value is outside the range of floats or return INF or -INF, >> or possibly the user should just check for infinite values themselves. > I was thinking about those features too. However, I'm concerned that proposing too many features will complicate the RFC and make it difficult to get it approved. Coming back to this point, I think these are basic features that people would expect to be there - I think I would find just slightly frustrating to start learning how to use a class like this and then find that it doesn't have these functions. Casting and calling `intval` or `floatval` all feel like slightly awkward workarounds that shouldn't be needed in a greenfield project. We know that the string inside the object is always a numeric string, so it should be easier to parse it as an int than to parse it as a date or a JSON document. Code doing the latter should stand out as odd looking. --------------tE60tlqG61W6NA9qjoAsnWNs Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
Hi again,

On 27/03/2024 00:40, Saki Takamachi wrote:
Do we also need `toFloat` and `toInt` functions? Seems like using explicit functions will be safer than casting.

For toInt I'd expect an exception if the value is outside the range of possible ints. For toFloat it might be nice to have a flag
argument to give the developer the choice of having it throw if the value is outside the range of floats or return INF or -INF,
or possibly the user should just check for infinite values themselves.
I was thinking about those features too. However, I'm concerned that proposing too many features will complicate the RFC and make it difficult to get it approved.

Coming back to this point, I think these are basic features that people would expect to be there - I think I would find just slightly frustrating to start learning how to use a class like this and then
find that it doesn't have these functions. Casting and calling `intval` or `floatval` all feel like slightly awkward workarounds that shouldn't be needed in a greenfield project. We know that the string
inside the object is always a numeric string, so it should be easier to parse it as an int than to parse it as a date or a JSON document. Code doing the latter should stand out as odd looking.


--------------tE60tlqG61W6NA9qjoAsnWNs--