Skip to content

Commit

Permalink
Use !(p >= 0.01) instead of p < 0.01 to catch NaNs
Browse files Browse the repository at this point in the history
Closes: ryankurte#1
  • Loading branch information
chrysn committed Nov 25, 2023
1 parent 3070707 commit 7051446
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/nist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub fn nist_freq_monobit(data: impl Iterator<Item = bool>) -> Result<f32, Error>
// Compute P-value
let p = libm::erfcf(s / libm::sqrtf(2.0));

// Check P value limit
if p < 0.01 {
// Check P value limit. The inverted logic ensures NaNs cause an error.
if !(p >= 0.01) {
return Err(Error::BadPValue(p));
}

Expand Down Expand Up @@ -86,8 +86,8 @@ pub fn nist_freq_block(
// Compute p
let p = 1.0 - nist_igamma(num_blocks as f32 / 2.0, x2 / 2.0);

// Check p value
if p < 0.01 {
// Check p value. The inverted logic ensures NaNs cause an error.
if !(p >= 0.01) {
return Err(Error::BadPValue(p));
}

Expand Down

0 comments on commit 7051446

Please sign in to comment.