Skip to content

Instantly share code, notes, and snippets.

@embarq
Last active September 20, 2016 08:00
Show Gist options
  • Save embarq/8116b821d2d839c42c5c12dca63a868f to your computer and use it in GitHub Desktop.
Save embarq/8116b821d2d839c42c5c12dca63a868f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
struct Pair {
double a;
double b;
};
void relativeFlow(Pair expected, Pair actual);
int main() {
Pair expected, actual;
expected.a = 0.895;
expected.b = 7.21;
actual.a = static_cast<double>(17) / 19;
actual.b = static_cast<double>(sqrt(52));
relativeFlow(expected, actual);
}
void relativeFlow(Pair expected, Pair actual) {
Pair delta, reflow;
delta.a = fabs(actual.a - expected.a);
delta.b = fabs(actual.b - expected.b);
reflow.a = (static_cast<double>(delta.a) / expected.a) * 100;
reflow.b = (static_cast<double>(delta.b) / expected.b) * 100;
printf("expected:\na = %f, b = %f\nactual:\na = %f, b = %f\ndelta:\na = %f, b = %f\nreflow:\na = %f, b = %f\n",
expected.a, expected.b, actual.a, actual.b, delta.a, delta.b, reflow.a, reflow.b);
if (reflow.a > reflow.b) {
printf("B is more accurate");
} else {
printf("A is mote accurate");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment