Skip to content

Conversation

@jl-wynen
Copy link
Member

Fixes #3236

@jl-wynen jl-wynen requested a review from nvaytet September 27, 2023 13:54
}
template <class T1, class T2>
constexpr auto operator/(const ValueAndVariance<T1> a, const T2 b) noexcept {
return ValueAndVariance{a.value / b, a.variance / (b * b)};
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible instead to use a trick like the order of operations above?
e.g. return ValueAndVariance{a.value / b, a.variance / b / b};?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be. But this would trade a multiplication for a division. So it would be slightly more expensive. But I don't know if that matters. Should I change it?

Copy link
Member

Choose a reason for hiding this comment

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

Should I change it?

I don't mind, your call. Tradeoff between performance and code simplicity.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other code needs a comment, so it's not necessarily simpler :-)

@jl-wynen jl-wynen merged commit 63c0a2f into main Oct 2, 2023
@jl-wynen jl-wynen deleted the variance-int-overflow branch October 2, 2023 14:37
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.

Negative variance in result of division by int32

3 participants