Re: Re: [RFC] [Discussion] [VOTE] Rounding Integers as int

From: Date: Mon, 18 Mar 2024 08:08:21 +0000
Subject: Re: Re: [RFC] [Discussion] [VOTE] Rounding Integers as int
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-122678@lists.php.net to get a copy of this message
Hi Vincent, On 17.03.24 22:59, Vincent Langlet wrote:
Hi, IMHO, the more meaningful cases of the RFC are missing : round(float, precision: >= 0): int|float // only cast to float for int overflow ceil(float): int|float // only cast to float for int overflow floor(float): int|float // only cast to float for int overflow Calling ceil or floor on integer is meaningless, because it will return the same value. The RFC should be "Prefer int as return value when possible". I do believe it's important to avoid unnecessary casts as much as possible and leave it up to the user making cast explicit than implicit else the behavior gets quite unpredictable.
Implicitly casting to float only happens on int underflow/overflow. Implicitly casting to int will never happen. As you say "Calling ceil or floor on integer is meaningless, because it will return the same value." this is already noted in the RFC and the functions will be a no-op in this case. Best regards, Marc

Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0x3936ABF753BC88CE.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
« previous php.internals (#122678) next »