Re: Understanding intval() and types conversion

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

 



> <somewhat-back-on-topic>
> So knowing this... is the fractional math how the BC Math extension for
> PHP works?  I'm really curious now.  It certainly makes things more
> clear for me if this is the case.
> </somewhat-back-on-topic>

Somewhat.

I'd more describe it as:

"You pick how many decimal points you want BC_MATH to use, and BC_MATH
will juggle the string representations of your numbers to keep that many
decimals valid"

So if you choose 10 decimal points, BC_MATH will represent 0.999... as:

"0.9999999999"

and 1 as "1.0000000000" and then it will add/subtract/multiply with that
many decimal points.

For scientific usage, to keep your rounding "correct" you always use an
"extra" decimal place than you are claiming as your accuracy, so that any
round-off errors happen in a decimal place you're not pretending is
"correct".

Note that all the operations happen as string-parsing, so you're basically
limited to the size of your RAM for your strings to fit.

And, as you might imagine, it is NOT going to be anything like as fast as
using built-in operators, since it has to munge all the strings to get
answers.

If you're an astrophysicist or a nuclear researcher, you NEED that
precision, though.

YMMV (but not by more than N decimal places)
:-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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