Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113089 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40206 invoked from network); 5 Feb 2021 13:08:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Feb 2021 13:08:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 65F311804F6 for ; Fri, 5 Feb 2021 04:52:42 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 5 Feb 2021 04:52:41 -0800 (PST) Received: by mail-oi1-f176.google.com with SMTP id u66so5356222oig.9 for ; Fri, 05 Feb 2021 04:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rq12nfbFrwWtyAdQKgZgsj3qmG9vT1gWoyiTsuvlujg=; b=GQmfpwefX/AOI7rfdkvgwGtmu4aWSfhJpa5O2GtA7pNCAm5HQApUTEMkL5BMdhw7NJ pd52+xVn3A1EzkOj+RkpX4oYxlW/BZNzVIDFXWBm5zTsRil5U2zPB5iidzTDTljRJ0Cq cRJoX/5OpnpLIznG05zTP9c86RATlNLyQh/pMYp0O9omVyuVS8Cibo4DB2ej4QY7NbJ0 4+9t2MnBknzgWdTaodgmESwag0nM9GOMFzvjKhbnI94eQPZflwyE/eUiO06FKBCVt6Ad +zO9ldDwEp33+PFn1CpctnHAH4Ha3P7HQt7lJfwZ+PrZfFy/3f6TsuqcUnirUTrHxC2v s9pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rq12nfbFrwWtyAdQKgZgsj3qmG9vT1gWoyiTsuvlujg=; b=gCz+qdyTUsCoz41HWUMRJMiHMaIpgTAt7Wy0Q73bstw3Fn/4M5tHZnAgvng4tgt7gS CexofPNLHrRe1yoxRkGdsK978/PB0qt2Al9kqzzpnB/lw/LxMR6vIkdAkI6R0WpXu2q5 EZ9OPR9s7kPwwcdvdcM4fWz+zWrzJDFUePK5BhUCHLkAP+L0tp/MGfWo5pb2RUT6WlGs PtqS+5QhgGx6rPRzH+ViEe3mFFILTH9vmvDEl13azCJjjLkjdIlcMBcDh03kM5SWI+IW PoObDe23HwlhTN6TgptjFnE8jgwwKbH3hRdnEcNc9g3bCp2qzqcK3O92TFeboTjDe+9W uRzQ== X-Gm-Message-State: AOAM531fbU57AUndNrSwNMLNHAm6Sx3YEESUwxXld+G/xkGxSNUTDzEo U1pQRBiCAYDcKc3ABL1VrDYMkA2/Dj5RPgWMaQ8= X-Google-Smtp-Source: ABdhPJwIJ19dKqySDvAh9bRv5P40eex7j49e+5FMRhvwUwrLA+5IgO4gnzfuUSFnsTiViCHn9ayGjFXBafXf4GS0BkY= X-Received: by 2002:aca:b286:: with SMTP id b128mr2938270oif.126.1612529560991; Fri, 05 Feb 2021 04:52:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 5 Feb 2021 13:52:29 +0100 Message-ID: To: AllenJB Cc: "G. P. B." , PHP internals Content-Type: multipart/alternative; boundary="000000000000ac3d0705ba964b53" Subject: Re: [PHP-DEV] [RFC] Warning for implicit float to int conversions From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000ac3d0705ba964b53 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 5 Feb 2021 at 11:56, AllenJB wrote: > (And after checking the manual, I'd also note here that round() also > returns a float, so how exactly does your example here work? Is it only > OK to explictly cast a float that's the return value of a function? Or > only explictly cast a float if the fractional part is .0? Is that viable > given the "inaccuracy" of floats? Or would it be better for PHP to have > some non-range/accuracy-sensitive representation for integers (and > decimals) here?) (and now we're getting into "why are we still using > floating point math by default in 2021" territory, so I'll stop right her= e) > Floats (doubles) can accurately represent all integers up to 2=E2=81=B5=C2= =B3, so there is no inaccuracy in this range; the result from round() or floor() could therefore be safely passed to (int) even if the cast operator checked for a 0 fractional part, which is what I'm advocating for. There are legitimate cases for explicitly casting floats to int. For > example floor() outputs a float, but in the context of the domain I'm > working I might know that the result is never going to exceed a certain > value and want the result explicitly as an int. Perfect, so (int) floor() would work wonders for you, even with the strict casting I'm talking about. And if the result does overflow an integer one day, I'm sure you'd be happy to know it by getting an exception, rather than getting silently ZERO: echo (int) 1e60; // 0 =E2=80=94 Benjamin --000000000000ac3d0705ba964b53--