See https://en.wikipedia.org/wiki/Relative_change_and_difference#Formulae
| 21 | |
| 22 | // See https://en.wikipedia.org/wiki/Relative_change_and_difference#Formulae |
| 23 | double getError(double exactVal, double approxVal) |
| 24 | { |
| 25 | double maxAbsVal = std::max(std::abs(exactVal), std::abs(approxVal)); |
| 26 | |
| 27 | // Both are ~0 |
| 28 | if(maxAbsVal < 1e-14) |
| 29 | { |
| 30 | return 0.0; |
| 31 | } |
| 32 | |
| 33 | double absError = std::abs(exactVal - approxVal); |
| 34 | |
| 35 | return std::min(absError, absError / maxAbsVal); |
| 36 | } |
| 37 | |
| 38 | // Checks if a is within margin of b |
| 39 | bool equalsWithinRange(double a, double b, double margin) |
no outgoing calls
no test coverage detected