Re: Fw: [PATCH] Fix for inconsistent float->int converting
| From: | Stig S. Bakken | Date: | Thu, 18 Oct 2001 23:11:33 +0000 |
| Subject: | Re: Fw: [PATCH] Fix for inconsistent float->int converting | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-68281@lists.php.net to get a copy of this message | ||
In cases like these I think PHP should do whatever C does. There's no
point in trying to be clever when casts overflow.
- Stig
Jeroen van Wolffelaar wrote:
>
> Resent, due to lack of feedback from my side ;)
>
> Andi replied:
> >>
> Why is it more correct to convert it to min/max values? I can't think of a
> case where this would make more sense to the developer.
> Also, there is a reason for the cast to unsigned int if the value is bigger
> that LONG_MAX.
> <<
>
> I think it makes sense. If a float is out-of-range, it can usually not be
> mod'd by 2**32, due to the nature of floats. Therefore, the only consistent
> way would be going to the nearest integer possible.
>
> Okay, because on most systems floats happen to be more precise than int's,
> you _can_ mod them by 2**32, but there is a quite significant possibility of
> having rounding errors. You cannot do integer-precision with floats.
>
> And it's inconsistent too, PHP int's are ranging from -2**31 to (2**31)-1,
> there is no such thing as unsigned integers. So why convert the float 3e9 to
> something way below zero?
>
> Additionally, a notice is a good idea here, just like what happens on
> division by zero: the most natural result is returned, and a notice is
> issued.
>
> --Jeroen
>
> ----- Original Message -----
> From: "Jeroen van Wolffelaar" <jeroen@A-Eskwadraat.nl>
> To: <zend-cvs@zend.com>
> Sent: Tuesday, October 02, 2001 2:39 AM
> Subject: [PATCH] Fix for inconsistent float->int converting
>
> > When a too-large float is converted to integer, it happens in a quite
> > random way. When float is out of range, PHP should stick to the min
> > resp. max values of integer.
> >
> > This patch will achieve this, I tested it succesfully.
> >
> > --Jeroen
> >
> > Jeroen van Wolffelaar
> > Jeroen@A-Eskwadraat.nl
> > http://www.A-Eskwadraat.nl/~jeroen
> >
>
> ------------------------------------------------------------------------
> Name: double.diff
> double.diff Type: unspecified type (application/octet-stream)
> Encoding: quoted-printable
>
> ------------------------------------------------------------------------
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net