Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122943 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 99A491A009C for ; Thu, 4 Apr 2024 21:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712265055; bh=R+Rdezfe874BrflSaqEdE3keI88v9uYWssvQFJQkVP8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OC8lxug5N0YlYQBpWz6AJbPqmYc1hlJ61ZxnUbUaipKEDGa73Z99Mh3LNnwmiFbop X6O5zVq2xGCknBvcwuFyjQlcxqEw+HVN5n3AecXk7vT2oDNeC14WbICoJahQ+Dqyka gytlbCrBFb/8oP6pnQVaCW/qctuyLlFGweYbumvq5W1fb9BkK0aUnzbO4P2PZQhH8D /RKFlq4us+VYP6nZP5udc7KcpuoTEBM8EzqodN4IOVp4lyI6UJ0KnhnuefqS/lk5El U5i8ch+Tq+Q8+ox8pCimpLouhXkp0owHaVvI0/H/C6IIzfL3c8z2aWR5YYa10CW6lg P04zkquSZAz2Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6A4BE180062 for ; Thu, 4 Apr 2024 21:10:54 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,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 mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Apr 2024 21:10:53 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2a074187a42so1081162a91.0 for ; Thu, 04 Apr 2024 14:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712265023; x=1712869823; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VcJstVlx4oz7nqIgkR7fW7g1dpldQ7gvJnClf4OA8dc=; b=afdTHOVdzcfAsAvS0pwnS/Y1R8NInc5kYqxGMiGtAPQk1nhNJmWSJlIc45W49oXISt FvO9VtZbqWwZ/g90wZXrGzaMwC/DyaMsx3ymC8judYVQ+m9lrlvWwpaXAjp6cvpGSnr2 Iu6cqF2GzQK8zaomsop5D1F+Wv9TjJoAd2qImwQrNJ8L9u2CLUv7bSY4kQlBQC38ZUNB tXe61sMv+q89CX2wXvs8nA/2qZo4euy0RW84xpUx6VeH3H5/BgtUslWLKh1FAeu/Zc5W Kiou8KS0oCgI60iA7beg99KfumWehWzvu/JMghjkOjROqb4eHshBibnXSIwcRpbN9ujL HO+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712265023; x=1712869823; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VcJstVlx4oz7nqIgkR7fW7g1dpldQ7gvJnClf4OA8dc=; b=WkpD56vlNRD5w5Z3XXZ+gladOUTESPGlyADw6SN17DyUpa815+IZdMN5wlSTCgUp6S aWgW7c70gGMkxjFicAElQZQSSHcY15NSTpYLS9uMtequmZ78YSbMUJk2DBPEH0gUrRNI 64yuWQX8hEssb3BSFbQrjmQQ8quF9Dspfw1cA4oQyRsTn3Jn4+ceWXt77B0GLhjBlYbY 1VSiFGmlPR9ZTp0BHrjPyxsKfzUoSl4eeTMayHc7ucFT7750AHtMd9dNOoC3c2JdJnYA weSw4bGiGKF7N1+JsyNTJhxkovA9KEBuVSQZ4emgxN6AyiFXWwcSZaum3U8qAEsI5oWA uwhg== X-Gm-Message-State: AOJu0YxQsU2tgshT7bQ9FcKSfx2k+5AYXyBmIiU2D6vamHBe0qpS6EtI CzB4AQ/EeNBEiHKgNKrCclZ2JmWlWqXg6+JHZiYvm5+fZvjTKjTAa7j+gVSkqarWTl6OIHbo64W cB594Xwq/Hyv2EuamV6IYA/01l7Isap3G X-Google-Smtp-Source: AGHT+IH2aFr82d2KoC/17p8csXobPnzH+ZHGTkXjkTTHr/ELoJSHasnr0RBTdKUrN/s+Gt6k09MwVywKDNxJEtvp7WI= X-Received: by 2002:a17:90a:2dc3:b0:2a2:fb06:bb87 with SMTP id q3-20020a17090a2dc300b002a2fb06bb87mr1552981pjm.21.1712265023126; Thu, 04 Apr 2024 14:10:23 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com> <91111e11ee72ffd18e1a1b2412246d00@gliadin.co.uk> <94B21565-9129-4379-A720-F4EDDD0A8D84@sakiot.com> <2c2f2731-acee-4c70-93d9-8ec6d9edc4db@redmagic.org.uk> In-Reply-To: <2c2f2731-acee-4c70-93d9-8ec6d9edc4db@redmagic.org.uk> Date: Thu, 4 Apr 2024 14:10:08 -0700 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: Barney Laurance Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000007707f606154bc491" From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000007707f606154bc491 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 4, 2024 at 1:59=E2=80=AFPM Barney Laurance wrote: > Hi again, > > On 27/03/2024 00:40, Saki Takamachi wrote: > > Do we also need `toFloat` and `toInt` functions? Seems like using explici= t functions will be safer than casting. > > For toInt I'd expect an exception if the value is outside the range of po= ssible 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 prop= osing too many features will complicate the RFC and make it difficult to ge= t 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` o= r > `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. > > > The class cannot guarantee that it can return a value in the type you request however, so the way that is handled would need to be decided. The value can easily be outside of the range of an int. Should it return a float silently in that case for `toInt()`? What if the value is beyond the range of a float? That would be a very rare situation, as floats can represent extremely large numbers (with very reduced accuracy), but I would expect it to throw an exception if that happened. Ideally an exception that I could catch and ignore, since I can almost surely deal with that error in most situations. What about a number that is so small that it can't fit in a float? Similar situation, though I expect it would occur slightly more often than a number being too large to fit in a float, even though it would also be rare. I think these helper functions belong in the RFC, but they aren't quite straightforward, which is what I think Saki was alluding to. Jordan --0000000000007707f606154bc491 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Apr 4, 2024 at 1:59=E2=80=AFP= M Barney Laurance <barney@redm= agic.org.uk> wrote:
=20 =20 =20
Hi again,

On 27/03/2024 00:40, Saki Takamachi wrote:
Do we also need `toFloat` and `toInt` functions? Seems like us=
ing 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 i=
s 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 concer=
ned that proposing too many features will complicate the RFC and make it di=
fficult 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 th= e 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.



The class cannot guara= ntee that it can return a value in the type you request however, so the way= that is handled would need to be decided. The value can easily be outside = of the range of an int. Should it return a float silently in that case for = `toInt()`? What if the value is beyond the range of a float? That would be = a very rare situation, as floats can represent extremely large numbers (wit= h very reduced accuracy), but I would expect it to throw an exception if th= at happened. Ideally an exception that I could catch and ignore, since I ca= n almost surely deal with that error in most situations.

What about a number that is so small that it can't fit in a floa= t? Similar situation, though I expect it would occur slightly more often th= an a number being too large to fit in a float, even though it would also be= rare.

I think these helper functions belong in th= e RFC, but they aren't quite straightforward, which is what I think Sak= i was alluding to.

Jordan
--0000000000007707f606154bc491--