Re: More math fun

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-08-12 at 14:59 -0700, Jim Lucas wrote:
> Jay Blanchard wrote:
> > abs($balanceTest) = 15.22
> > abs($oldLineArray[16]) = 15.22
> > 
> > $diff = abs($balanceTest) - abs($oldLineArray[16]);
> > echo abs($diff) . "\n";
> > 
> > 1.7763568394E-15
> > 
> > WTF? This should be a big fat 0
> > 
> 
> I do not see how it makes any difference if $balanceTest and $oldLineArray[16] 
> are strings in the beginning.  In line that does the subtraction, they would 
> have been converted to floats automagically by abs().  If you look at the 
> manual for this function, you will see that the returned value is either a 
> float or integer bases on the input type.  Float would return a float. 
> Anything else would return a integer.
> 
> BTW - if I setup the following:
> 
> <?php
> 
> $balanceTest = '15.22';  # A string
> $oldLineArray[16] = 15.22; # A float
> 
> $diff = abs($balanceTest) - abs($oldLineArray[16]);
> echo abs($diff) . "\n";
> echo gettype(abs($diff)) . "\n";
> 
> # 1.7763568394E-15
> 
> ?>
> 
> I get 0 and 'double'

Yeah, I was probably thinking abs( $balanceTest - $oldLineArray[16] )
versus what was actually present. But either way, I get 0 doing the
above also when I set up the values... so I have no idea how it's not
working for Jay.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux