How to code defensively against the Microsoft C26451 (arithmetic overflow) warning in my example? I feel like this should be trivial to fix. So frustrating!
// Linear interpolation
// target - the target point, 0.0 - 1.0
// x... - two values {X1} {X2}
inline static double Linear(float target, double x1, double x2) {
return (target * x2) + ((1.0 - (double)target) * x1);
}
I read through Arithmetic overflow: Using operator '*' on a 4 byte value then casting the result to a 8 byte value but can't seem to fix my C26451 warning: "Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2).
What would I do to remove the warning?
The Microsoft doc on their compile error did not really help. https://learn.microsoft.com/en-us/cpp/code-quality/c26451