Skip to content
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

Enable customizable precision for allocations #1114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

faraquet
Copy link

@faraquet faraquet commented Oct 9, 2024

Problem

Me and @spariev have found that the allocation logic fails to function properly with large arrays. In a real production scenario, we encountered a process freeze followed by an error.

Money::Allocation.generate(246.4, [
  81.29, 81.29, 81.29, 81.29,
  234.8, 234.8, 234.8, 234.8,
  90.36, 90.36, 90.36, 90.36,
  90.36, 90.36, 90.36, 90.36,
  90.36, 90.36, 90.36, 90.36,
  90.36, 90.36, 90.36, 90.36,
  90.36, 90.36, 90.36, 90.36,
  90.36
], false)

The reason is that when the number of parts exceeds 15, there is an infinite number of digits after the decimal point.

Solution

The generate method has been refactored by renaming the whole_amounts parameter to rounding_mode for better clarity. This allows more flexible rounding options, supporting booleans and custom decimal precision.

@faraquet faraquet force-pushed the force-default-rounding-to-allocation branch from e9ee918 to 22864ef Compare October 9, 2024 10:55
@faraquet
Copy link
Author

@semmons99 @antstorm
Hi 👋 , could you please take a look? I'm not sure who is more responsible for reviewing, so I'm tagging you because you approved the recent commits. I'm happy to discuss these changes. Thanks!

@faraquet faraquet force-pushed the force-default-rounding-to-allocation branch 2 times, most recently from 86dadae to 946a25e Compare October 11, 2024 09:57
@faraquet faraquet changed the title Enable and enforce customizable allocation precision for handling large arrays Enable customizable allocation precision Oct 11, 2024
@faraquet faraquet force-pushed the force-default-rounding-to-allocation branch from 946a25e to 070b7d4 Compare October 11, 2024 10:01
@faraquet faraquet changed the title Enable customizable allocation precision Enable customizable precision for allocations Oct 11, 2024
@faraquet faraquet force-pushed the force-default-rounding-to-allocation branch from 070b7d4 to b1cd3d0 Compare October 11, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant