On Fri, May 02, 2008 at 01:03:45PM -0700, Todd Ruth wrote: > On Fri, 2008-05-02 at 11:41 -0700, Rasmus Lerdorf wrote: > > Stefan Walk wrote: > > > And you'll quickly see that the "cast to string before comparision" is a > > > bad idea, because: > > > $ php -dprecision=1 -r 'var_dump((string)1.4 == (string)1.1);' > > > bool(true) > > > > > > Having display settings affect comparisions seems like a really bad idea > > > to me ;) > > > > Yup, it would be a fatal flaw in the language if that ever came to be. > > > > -Rasmus > > Most people don't care about floating numbers beyond a certain > number of digits. If precision were the only ini setting that > gave us an idea of how much the person cared, I think it would > be fair to use the setting or introduce a new setting. As it > happens, there is another setting. How would you feel about > this returning true: > > php -dserialize_precision=1 -r 'var_dump(1.4 == 1.1);' > > Setting serialize_precision to 1 is a very strong statement of > not caring about those digits. Personally, I don't care about > more than about 6 digits and I don't do much math, so I could > set it to 8 digits and be happy. Not everyone has the luxury > of controlling ini settings, but for those that do, this > would be much nicer than having
Hmmm, what you are talking about is implying: $a == $b be implemented as: abs($a - $b) < (max(abs($a), abs($b)) / EPSILON) Where EPSILON is some sort of accuracy factor. It might be possible to implement this easier/faster at a machine code level. The trouble is that doing something like this would be global and might mess up some code written elsewhere. Mind you: any programmer going '$a == $b' on true floating point has got to expect rubbish. This is making things easier for the naive/novice programmer. In this case I don't think that it realy helps since the naive programmer isn't going to have a clue about choosing a good value for EPSILON. Best leave it the way that it is. -- Alain Williams Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Chairman of UKUUG: http://www.ukuug.org/ #include <std_disclaimer.h> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php