Skip to content

Commit beec7bf

Browse files
committed
small cleanup to make compute_half_gap nicer
1 parent 6d16774 commit beec7bf

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

antithesis_sdk.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,22 +603,20 @@ namespace antithesis {
603603
get_lib_handler().output(catalog);
604604
}
605605

606-
std::pair<NumericValue, bool> compute_half_gap(Value value) {
607-
NumericValue left = value.first;
608-
NumericValue right = value.second;
606+
std::pair<NumericValue, bool> compute_half_gap(NumericValue left, NumericValue right) {
609607
// An extremely baroque way to compute (left - right) / 2, rounded toward 0, without overflowing or underflowing
610608
if (std::is_integral_v<NumericValue>) {
611609
// If both numbers are odd then the gap doesn't change if we subtract 1 from both sides
612610
// Also subtracting 1 from both sides won't underflow
613611
if (left % 2 == 1 && right % 2 == 1)
614-
return compute_half_gap({ left - 1, right - 1});
612+
return compute_half_gap( left - 1, right - 1);
615613
// If one number is odd then we subtract 1 from the larger number
616614
// This rounds the computation toward 0 but again won't underflow
617615
if (left % 2 == 1 || right % 2 == 1) {
618616
if (left > right) {
619-
return compute_half_gap({ left - 1, right });
617+
return compute_half_gap( left - 1, right );
620618
} else {
621-
return compute_half_gap({ left, right - 1});
619+
return compute_half_gap( left, right - 1 ` );
622620
}
623621
}
624622
// At this point both numbers are even, so the midpoint calculation is exact
@@ -671,7 +669,7 @@ namespace antithesis {
671669
}
672670

673671
[[clang::always_inline]] inline void send_guidance(Value value) {
674-
std::pair<NumericValue, bool> half_gap = compute_half_gap(value);
672+
std::pair<NumericValue, bool> half_gap = compute_half_gap(value.first, value.second);
675673
if (should_send_value(half_gap)) {
676674
extreme_half_gap = half_gap;
677675
std::string id = make_key(this->message, this->location);

0 commit comments

Comments
 (0)