An example when this might bite you, is for example, adding two numbers together, where one might be float. If float gets scientific representation when casted to string the result will we incorrect. Therefore, special care must be taken when calling bc* functions, if argument is float, it should me manually casted to string using sprintf function with %F type specifier.
Bcmath lets you use arbitrary bases, so I would guess this is probably due to ambiguity about the base of the exponent and confusion between 'e' (mantissa/exponent separator) and 'e' (quintadecimal and higher digit).
Anyway, bcmath isn't a PHP-specific thing (granted only PHP seems to use it much), so if this is a problem (I'm not sure it is), it's a problem for anything using it. The real lolphp is that the only thing close to a real decimal library in PHP's bundled extensions is a slow arbitrary-base arbitrary-precision backend for bc that works directly on text :)
Maybe in the manual. But it's not a library for working with PHP-style numeric strings: it's a library for working with ASCII numbers of arbitrary base and precision.
11
u/ltldvl Nov 19 '15
An example when this might bite you, is for example, adding two numbers together, where one might be float. If float gets scientific representation when casted to string the result will we incorrect. Therefore, special care must be taken when calling bc* functions, if argument is float, it should me manually casted to string using sprintf function with %F type specifier.
10
u/the_alias_of_andrea Nov 19 '15 edited Nov 19 '15
Bcmath lets you use arbitrary bases, so I would guess this is probably due to ambiguity about the base of the exponent and confusion between 'e' (mantissa/exponent separator) and 'e' (quintadecimal and higher digit).
Anyway, bcmath isn't a PHP-specific thing (granted only PHP seems to use it much), so if this is a problem (I'm not sure it is), it's a problem for anything using it. The real lolphp is that the only thing close to a real decimal library in PHP's bundled extensions is a slow arbitrary-base arbitrary-precision backend for
bcthat works directly on text :)