PhpUnitsOfMeasure / php-units-of-measure

A library for handling physical quantities and the units of measure in which they're represented.
MIT License
305 stars 77 forks source link

Use bc math #43

Open mathewrapid opened 9 years ago

mathewrapid commented 9 years ago

http://php.net/manual/en/book.bc.php

triplepoint commented 7 years ago

Yeah, that's probably a good idea. I'll want to do some profiling to make sure we're not slowing things down too much, but I think this is probably an important improvement.

hipsterjazzbo commented 6 years ago

@triplepoint I've done some benchmarks out of curiosity, and for fewer than ~1,000 operations it seems to not really make a difference — either will take < 1ms. BCMath is a lot slower if you're wanting to do tens of thousands of operations, but we're talking ~20ms vs ~2ms, which seems reasonable to me within the intended purpose of this library.

There is also the issue that BCMath is not included by default with PHP (except on windows for some reason), but I think it seems reasonable to require it in order to be able to get accurate results out and avoid floating-point errors.

If that sounds reasonable to you, I'd be happy to go through and change everything to BCMath.

soyuka commented 6 years ago

What would it take to enable BCMath if available and the default if not?

TomA-R commented 1 year ago

hey @triplepoint this would be really useful, is this on the roadmap?

soleson commented 1 year ago

I've created a patch that can be installed via composer-patches. The patch defaults the precision to the value set by php. This was a quick-and-dirty fix, so I'm hoping others can review and improve the efficiency. php-unit-of-measure-bcmath-support.patch