-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use BCMath (where available) for all float arithmetic #115
base: master
Are you sure you want to change the base?
Conversation
I measured length() function with BCMath enabled and disabled and the difference is more than significant. $geom = GeoPHP::load(file_get_contents('20120702.gpx'));
$start = microtime(true);
for($i=0; $i < 50; $i++) {
$geom->length();
}
var_dump(microtime(true) - $start); BCMath enabled: 21.463 sec |
Whoa, 21 seconds is a long time! What's in that file? BCMath is going to be more intensive, yes. But it is also going to be more precise. For some that might matter more than speed. Perhaps we should include some ability to globally enable/disable bcmath usage within GeoPHP? Also, there are some issues with LineString::greatCircleLength() and LineString::haversineLength() methods: #114 (comment) I posted that to the other issue, but forgot to update this pull request. This should be put on hold until that's fixed. |
Just a small tracklog from the tests/input folder :) |
…, centroid(), and pointInPolygon().
…gth(), greatCircleLength(), haversineLength(), lineSegmentIntersect().
…es a lot of decimal places (ie: latitude/longitude).
… that uses a lot of decimal places (ie: latitude/longitude)." This reverts commit 1298694.
Rebased onto latest master, fixed a bug, and removed the This PR is still not ready to be merged, however.
|
@BathoryPeter I wonder if this will be more reasonable without the |
FYI: I kept my commits separate to show the reasoning behind these recent changes, but we can plan to squash them into a single commit when it's time to merge. |
Currently 2 tests are failing:
Both have to do with calculated lengths of |
@mstenta I wonder if we should open this PR against the new fork of this repo: https://github.com/itamair/geoPHP |
@paul121 Yea probably. Although maybe we should fix the failing tests first, and review it all again. It's been a long time since I've looked at this, although we've been using it in farmOS for almost 10 years now! |
Hi @mstenta @paul121 I've prepared a patch but don't have permission to push it here. Could you update this PR with my changes? I've attached a patch file here. Note the patch only covers the functions that fail for us. There may well be other places where the float should be converted to string before being passed to a bcmath function. Thanks! |
Thanks for reporting that @peacog! I see what you mean about the potential issue. However, I think the patch would need some more work before we can consider merging it into this PR.
I think we'll need to do more research on the proper way to prevent the issue you encountered. |
Thanks @mstenta. I was looking for a quick way to patch the problem on our site, hence the partial patch.
|
@mstenta as I said in my comment here this error might have been introduced with PHP 8. We could solve the precision problem by using this float_to_string function instead of number_format
|
See the original issue that spawned this branch: #114