Re: [PHP-DEV] PHP can't compare...

2001-12-11 Thread George Whiffen
Zeev Suraski wrote: > > Your suggestion does make sense, but it's probably impractical at this > point, as it requires a rewrite of pretty much every function or piece of > code that deals with floats. It sounds like a noble cause, but one that > would have to wait for now :) > > Zeev > Uhh s

Re: [PHP-DEV] PHP can't compare...

2001-12-11 Thread Zeev Suraski
Your suggestion does make sense, but it's probably impractical at this point, as it requires a rewrite of pretty much every function or piece of code that deals with floats. It sounds like a noble cause, but one that would have to wait for now :) Zeev At 21:12 10/12/2001, George Whiffen wrot

Re: [PHP-DEV] PHP can't compare...

2001-12-10 Thread Pierre-Alain Joye
> But my suggestion only produces rounding errors when the developer is trying to >operate on floats > with results of precision greater than 14 decimals. These developers should already >know they MUST > use bc or gmp in such cases. > > You may say it should be "up to the developer", but th

Re: [PHP-DEV] PHP can't compare...

2001-12-10 Thread George Whiffen
Rasmus Lerdorf wrote: > > > But I don't want to do this! I want to compare php numbers, which can be either >strings or floats, > > in php! This already works fine when the php number is "passed" as a string, I >just want it to also > > work when it's passed as a float/double! > > Which is n

Re: [PHP-DEV] PHP can't compare...

2001-12-10 Thread Rasmus Lerdorf
> But I don't want to do this! I want to compare php numbers, which can be either >strings or floats, > in php! This already works fine when the php number is "passed" as a string, I just >want it to also > work when it's passed as a float/double! Which is not possible. > floor(string(8.2 -

Re: [PHP-DEV] PHP can't compare...

2001-12-10 Thread George Whiffen
Rasmus, You're right someone doesn't get it, but I'm still not convinced that it's me!! I do understand that "0.1 cannot be finitely expressed in binary" and in particular that "You can't compare floating points in C". But I don't want to do this! I want to compare php numbers, which can be e

Re: [PHP-DEV] PHP can't compare...

2001-12-07 Thread Rasmus Lerdorf
I guess you didn't understand any of the explanations you got to this. #6220 is not a bug. Computers can not represent floating point values accurately, only to a certain level of precision. Ergo there is no such thing as precisely 0.1 and any function, such as floor(), which relies on a nu

Re: [PHP-DEV] PHP can't compare...

2001-12-07 Thread George Whiffen
Pierre/Rasmus/Zeev, After a little more thought, it seems to me that, my problem, Bug 6220 and Matthew's original problem at the start of this thread are all REAL LIVE BUGS. As Pierre suggested, php seems to handle floating points fine 99% of the time with in its documented precision (14 deci

Re: [PHP-DEV] PHP can't compare...

2001-12-06 Thread Pierre-Alain Joye
On Thu, 06 Dec 2001 18:03:23 + George Whiffen <[EMAIL PROTECTED]> wrote: > Matthew, > > You are absolutely right, we have to do something about handling money better before >anyone else > notices that 0.7 plus 0.1 is not 0.8 with php! (I've already had an e-commerce user >notice that > th

Re: [PHP-DEV] PHP can't compare...

2001-12-06 Thread Rasmus Lerdorf
> You are absolutely right, we have to do something about handling money better before >anyone else > notices that 0.7 plus 0.1 is not 0.8 with php! (I've already had an e-commerce user >notice that > their account balance is misquoted because 82 - 2 became 79 because of this). If you are deal

Re: [PHP-DEV] PHP can't compare...

2001-12-06 Thread Zeev Suraski
I don't think that a PR like the one you raise is likely. Mostly all other languages behave in the same way. Even other software components, such as databases, often have this issue, unless you use string base representation. Zeev At 20:03 06/12/2001, George Whiffen wrote: >Matthew, > >You a

Re: [PHP-DEV] PHP can't compare...

2001-12-06 Thread George Whiffen
Matthew, You are absolutely right, we have to do something about handling money better before anyone else notices that 0.7 plus 0.1 is not 0.8 with php! (I've already had an e-commerce user notice that their account balance is misquoted because 82 - 2 became 79 because of this). Looking throu

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread derick
On Wed, 5 Dec 2001, Matthew Hagerty wrote: > The issue that kicked this whole thing off came about because I have to > deal with money values. PHP only has integers and doubles for dealing with > numbers, not counting boolean (unless I missed one), so you can't really > reliably represent, say $

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread Zeev Suraski
A couple of things: (a) doubles are actually more accurate than floats (more digits). Because of that, they're more prone to the exact comparison errors :) I wouldn't hold my breath about float getting into the language... (b) To do what you want, you can still use bcmath or one of the other

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread Matthew Hagerty
At 12:09 PM 12/5/2001 +0200, Zeev Suraski wrote: >At 00:38 05/12/2001, Matthew Hagerty wrote: >>Okay, then why when I ask PHP to show me the value of $fFloat1, do I get >>this: >> >>printf("%f", $fFloat1); -> 63.67 >> >>Not some long draw out number like 63.671 or even >>63.6699

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread Pierre-Alain Joye
Hello, Thank's Zeev, I was afraid of I m the only one who learned this kind of old stuffs (but basics) langages rules. :)) pa -- PHP Development Mailing List To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread Stig Venaas
On Wed, Dec 05, 2001 at 12:09:33PM +0200, Zeev Suraski wrote: > There's no clean 3.55, there simply isn't. It's just how computers > work. The only way to do what you're asking for is to switch to a whole > different string-based representation, which is going to slow things down > very consi

Re: [PHP-DEV] PHP can't compare...

2001-12-05 Thread Zeev Suraski
At 00:38 05/12/2001, Matthew Hagerty wrote: >Okay, then why when I ask PHP to show me the value of $fFloat1, do I get this: > >printf("%f", $fFloat1); -> 63.67 > >Not some long draw out number like 63.671 or even >63.669... If PHP uses precision past the 6 digit then it need

Re: [PHP-DEV] PHP can't compare...

2001-12-04 Thread Stig Venaas
On Tue, Dec 04, 2001 at 05:38:10PM -0500, Matthew Hagerty wrote: > I'm going to stop ranting and go check PHP's source, make some tests in C > and such. But with this type of number representation, PHP becomes > inaccurate in all but the most simple use of numbers. I find this surprising as we

Re: [PHP-DEV] PHP can't compare...

2001-12-04 Thread Pierre-Alain Joye
> However, even if the number is not stored as indicated, ie. 3.551 > instead of a clean 3.55000, then why does PHP take the liberty to chop > off that precision when converting to a string? And why is that precision > not put back on when going back to a double? It is not put bac

Re: [PHP-DEV] PHP can't compare...

2001-12-04 Thread Matthew Hagerty
Okay, then why when I ask PHP to show me the value of $fFloat1, do I get this: printf("%f", $fFloat1); -> 63.67 Not some long draw out number like 63.671 or even 63.669... If PHP uses precision past the 6 digit then it needs to show me that it does. I can't agree with yo

Re: [PHP-DEV] PHP can't compare...

2001-12-04 Thread Pierre-Alain Joye
On Tue, 4 Dec 2001 23:05:04 +0100 (CET) Derick Rethans <[EMAIL PROTECTED]> wrote: > Hello, > > this is how floating point numbers work. > > 3.55 as float is not 'exactly' 3.55, but it is stored in memory as an as > good as possible representation, something like 3.551 perhaps. > > If y

Re: [PHP-DEV] PHP can't compare...

2001-12-04 Thread Derick Rethans
Hello, this is how floating point numbers work. 3.55 as float is not 'exactly' 3.55, but it is stored in memory as an as good as possible representation, something like 3.551 perhaps. If you simply compare this: 3.550001 + 60.12001 != 63.69 so that's why

[PHP-DEV] PHP can't compare...

2001-12-04 Thread Matthew Hagerty
Greetings, Explain to me why the first condition fails! Thanks, Matthew -- PHP Development Mailing List To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]