Fw: [PATCH] Fix for inconsistent float->int converting

From: Date: Thu, 18 Oct 2001 20:38:04 +0000
Subject: Fw: [PATCH] Fix for inconsistent float->int converting
Groups: php.dev 
Request: Send a blank email to php-dev+get-68274@lists.php.net to get a copy of this message
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 >

Attachment: [application/octet-stream] double.diff
« previous php.dev (#68274) next »