3 #include "test_macros.h"
5 #define LOG_EPSILON 1500
8 main(int argc, char *argv[])
13 lmath = logmath_init(1.0001, 0, 1);
15 printf("log(1e-150) = %d\n", logmath_log(lmath, 1e-150));
16 TEST_EQUAL_LOG(logmath_log(lmath, 1e-150), -3454050);
17 printf("exp(log(1e-150)) = %e\n",logmath_exp(lmath, logmath_log(lmath, 1e-150)));
18 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 1e-150)), 1e-150);
19 printf("log(1e-48) = %d\n", logmath_log(lmath, 1e-48));
20 printf("exp(log(1e-48)) = %e\n",logmath_exp(lmath, logmath_log(lmath, 1e-48)));
21 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 1e-48)), 1e-48);
22 printf("log(42) = %d\n", logmath_log(lmath, 42));
23 TEST_EQUAL_LOG(logmath_log(lmath, 42), 37378);
24 printf("exp(log(42)) = %f\n",logmath_exp(lmath, logmath_log(lmath, 42)));
25 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 42)), 42);
26 printf("log(1e-3 + 5e-3) = %d l+ %d = %d\n",
27 logmath_log(lmath, 1e-3),
28 logmath_log(lmath, 5e-3),
29 logmath_add(lmath, logmath_log(lmath, 1e-3),
30 logmath_log(lmath, 5e-3)));
31 printf("log(1e-3 + 5e-3) = %e + %e = %e\n",
32 logmath_exp(lmath, logmath_log(lmath, 1e-3)),
33 logmath_exp(lmath, logmath_log(lmath, 5e-3)),
34 logmath_exp(lmath, logmath_add(lmath, logmath_log(lmath, 1e-3),
35 logmath_log(lmath, 5e-3))));
36 TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
37 logmath_log(lmath, 5e-48)),
38 logmath_log(lmath, 6e-48));
39 TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
40 logmath_log(lmath, 42)),
41 logmath_log(lmath, 42));
43 rv = logmath_write(lmath, "tmp.logadd");
46 lmath = logmath_read("tmp.logadd");
48 printf("log(1e-150) = %d\n", logmath_log(lmath, 1e-150));
49 TEST_EQUAL_LOG(logmath_log(lmath, 1e-150), -3454050);
50 printf("exp(log(1e-150)) = %e\n",logmath_exp(lmath, logmath_log(lmath, 1e-150)));
51 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 1e-150)), 1e-150);
52 printf("log(1e-48) = %d\n", logmath_log(lmath, 1e-48));
53 printf("exp(log(1e-48)) = %e\n",logmath_exp(lmath, logmath_log(lmath, 1e-48)));
54 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 1e-48)), 1e-48);
55 printf("log(42) = %d\n", logmath_log(lmath, 42));
56 TEST_EQUAL_LOG(logmath_log(lmath, 42), 37378);
57 printf("exp(log(42)) = %f\n",logmath_exp(lmath, logmath_log(lmath, 42)));
58 TEST_EQUAL_FLOAT(logmath_exp(lmath, logmath_log(lmath, 42)), 41.99);
59 printf("log(1e-3 + 5e-3) = %d l+ %d = %d\n",
60 logmath_log(lmath, 1e-3),
61 logmath_log(lmath, 5e-3),
62 logmath_add(lmath, logmath_log(lmath, 1e-3),
63 logmath_log(lmath, 5e-3)));
64 printf("log(1e-3 + 5e-3) = %e + %e = %e\n",
65 logmath_exp(lmath, logmath_log(lmath, 1e-3)),
66 logmath_exp(lmath, logmath_log(lmath, 5e-3)),
67 logmath_exp(lmath, logmath_add(lmath, logmath_log(lmath, 1e-3),
68 logmath_log(lmath, 5e-3))));
69 TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
70 logmath_log(lmath, 5e-48)),
71 logmath_log(lmath, 6e-48));
72 TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
73 logmath_log(lmath, 42)),
74 logmath_log(lmath, 42));