Skip to content

Commit a42025d

Browse files
committed
minor
1 parent bf19669 commit a42025d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/utilities/snp_hwe.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <cassert>
2-
#include <cmath>
32
#include <cstdint>
43
#include <limits>
54

@@ -44,12 +43,13 @@ double p_hwe_excess_het(int obs_hets, int obs_hom1, int obs_hom2)
4443

4544
std::vector<double> het_probs(rare_copies + 1, 0.0);
4645

47-
// start at midpoint
48-
double mid_double = static_cast<double>(rare_copies) * static_cast<double>(2 * genotypes - rare_copies) /
49-
static_cast<double>(2 * genotypes);
46+
// start at midpoint.
47+
// Note: This code was modified from its original source to prevent integer overflow with 100,000+ genotypes
48+
double mid_double = static_cast<double>(rare_copies) *
49+
(static_cast<double>(2 * genotypes - rare_copies) / static_cast<double>(2 * genotypes));
5050

5151
assert(mid_double < static_cast<double>(std::numeric_limits<int>::max()));
52-
int mid = std::lround(mid_double);
52+
int mid = static_cast<int>(mid_double);
5353

5454
// check to ensure that midpoint and rare alleles have same parity
5555
if ((rare_copies & 1) ^ (mid & 1))

0 commit comments

Comments
 (0)