Ticket #9962: main.cpp

File main.cpp, 1.6 KB (added by markh, 6 years ago)

Small example of pow returning nan instead of the expected inf

Line 
1// Standard C headers
2#include <stdio.h>
3#include <math.h>
4
5int main(int argc, char **argv) {
6
7 printf("Tests with pow:\n");
8 double powResult = pow(-1004.3, 1e200);
9 printf("pow(-1004.3, 1e200) = %f\n", powResult);
10
11 if isinf(powResult) {
12 printf("Overflow for pow(-1004.3, 1e200)\n");
13 }
14
15 powResult = pow(-34.84, 1e200);
16 printf("pow(-34.84, 1e200) = %f\n", powResult);
17
18 if isinf(powResult) {
19 printf("Overflow for pow(-34.84, 1e200)\n");
20 }
21
22 powResult = pow(-1.2345678901234e+200, 1e200);
23 printf("pow(-1.2345678901234e+200, 1e200) = %f\n", powResult);
24
25 if isinf(powResult) {
26 printf("Overflow for pow(-1.2345678901234e+200, 1e200)\n");
27 }
28
29 powResult = pow(-1.2345678901234e-200, 1e200);
30 printf("pow(-1.2345678901234e-200, 1e200) = %f\n", powResult);
31
32 if isinf(powResult) {
33 printf("Overflow for pow(-1.2345678901234e-200, 1e200)\n");
34 }
35
36
37 printf("\nTests with multiplication for comparison:\n");
38 double mulResult = -1004.3 * 1e200;
39 printf("-1004.3 * 1e200 = %f\n", mulResult);
40
41 if isinf(mulResult) {
42 printf("Overflow for -1004.3 * 1e200\n");
43 }
44
45 mulResult = -34.84 * 1e200;
46 printf("-34.84 * 1e200 = %f\n", mulResult);
47
48 if isinf(mulResult) {
49 printf("Overflow for -34.84 * 1e200\n");
50 }
51
52 mulResult = -1.2345678901234e+200 * 1e200;
53 printf("-1.2345678901234e+200 * 1e200 = %f\n", mulResult);
54
55 if isinf(mulResult) {
56 printf("Overflow for -1.2345678901234e+200 * 1e200\n");
57 }
58
59 mulResult = -1.2345678901234e-200 * 1e200;
60 printf("-1.2345678901234e-200 * 1e200 = %f\n", mulResult);
61
62 if isinf(mulResult) {
63 printf("Overflow for -1.2345678901234e-200 * 1e200\n");
64 }
65
66 return 0;
67
68}