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

add log_product #7

Merged
merged 4 commits into from
Jul 9, 2024
Merged

add log_product #7

merged 4 commits into from
Jul 9, 2024

Conversation

cscherrer
Copy link
Contributor

This PR adds log_product:

pub fn log_product(data: impl Iterator<Item = f64>) -> f64 {
    let mut result = 0.0;
    let mut prod = 1.0;
    for x in data {
        let next_prod: f64 = x * prod;
        if next_prod.is_normal() {
            prod = next_prod;
        } else {
            if x.is_zero() {
                return f64::NEG_INFINITY;
            }
            result += prod.ln();
            prod = x;
        }
    }
    result + prod.ln()
}

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.38%. Comparing base (b5395e9) to head (b3501b4).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   81.34%   81.38%   +0.04%     
==========================================
  Files          90       90              
  Lines       18255    18305      +50     
  Branches    18255    18305      +50     
==========================================
+ Hits        14849    14898      +49     
- Misses       3280     3281       +1     
  Partials      126      126              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cscherrer cscherrer requested a review from BaxterEaves July 9, 2024 17:48
Copy link
Contributor

@BaxterEaves BaxterEaves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for all the tests

@cscherrer cscherrer merged commit 8fc9c8d into master Jul 9, 2024
9 of 10 checks passed
@cscherrer cscherrer deleted the cs-log_product branch July 9, 2024 17:59
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.

2 participants