| 1 |
#include <stdio.h> |
| 2 |
#include <math.h> |
| 3 |
#include <stdbool.h> |
| 4 |
|
| 5 |
#define def_func(name, op) \ |
| 6 |
bool name(double left, double right) { \ |
| 7 |
return left op right; \ |
| 8 |
} |
| 9 |
|
| 10 |
def_func(eq, ==) |
| 11 |
def_func(ne, !=) |
| 12 |
def_func(lt, <) |
| 13 |
def_func(le, <=) |
| 14 |
def_func(gt, >) |
| 15 |
def_func(ge, >=) |
| 16 |
|
| 17 |
struct { |
| 18 |
const char *name; |
| 19 |
bool (*func)(double left, double right); |
| 20 |
} functions[] = { |
| 21 |
{ "==", eq }, |
| 22 |
{ "!=", ne }, |
| 23 |
{ "< ", lt }, |
| 24 |
{ "<=", le }, |
| 25 |
{ "> ", gt }, |
| 26 |
{ ">=", ge }, |
| 27 |
{ 0, 0 } |
| 28 |
}; |
| 29 |
|
| 30 |
int main() |
| 31 |
{ |
| 32 |
double values[] = { |
| 33 |
-sqrt(-1), // nan |
| 34 |
sqrt(-1), // -nan |
| 35 |
-log(0.0), // inf |
| 36 |
log(0.0) // -inf |
| 37 |
}; |
| 38 |
double compare[] = { 2.0, |
| 39 |
-sqrt(-1), // nan |
| 40 |
sqrt(-1), // -nan |
| 41 |
-log(0.0), // inf |
| 42 |
log(0.0) // -inf |
| 43 |
}; |
| 44 |
|
| 45 |
int i, j, k; |
| 46 |
|
| 47 |
for (i = 0; i < 4; i++) { |
| 48 |
for (j = 0; j < 5; j++) { |
| 49 |
for (k = 0; functions[k].name != NULL; k++) { |
| 50 |
printf("%g %s %g -> %s\n", values[i], |
| 51 |
functions[k].name, |
| 52 |
compare[j], |
| 53 |
functions[k].func(values[i], compare[j]) ? "True" : "False"); |
| 54 |
} |
| 55 |
printf("\n"); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |