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

Use running averages to avoid overflows #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

BWStearns
Copy link
Owner

The idea here is to use a running average instead of summing all the inputs. This adds an extra division operation for each element, but it has the benefit of not being able to overflow. It is currently failing for extremely large numbers.

@BWStearns
Copy link
Owner Author

I need to read up on how libraries should handle imprecision. I can't eyeball test_safe_circadian_with_big_numbers and know whether that difference is acceptable, but at least for test_with_many_reasonably_sized_numbers it seems like it's in the realm of acceptable.

---- tests::test_safe_circadian_with_big_numbers stdout ----
thread 'tests::test_safe_circadian_with_big_numbers' panicked at 'assertion failed: `(left == right)`
  left: `1.7014118e38`,
 right: `1.7014117e38`', src/lib.rs:191:9

---- tests::test_with_many_reasonably_sized_numbers stdout ----
thread 'tests::test_with_many_reasonably_sized_numbers' panicked at 'assertion failed: `(left == right)`
  left: `1499.6367`,
 right: `1500.0`', src/lib.rs:181:9


failures:
    tests::test_safe_circadian_with_big_numbers
    tests::test_with_many_reasonably_sized_numbers

@BWStearns
Copy link
Owner Author

Looks like the safe version works without a notable performance penalty.

image image

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