File: test_log_int8.c

package info (click to toggle)
sphinxbase 0.8%2B5prealpha-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,592 kB
  • ctags: 3,296
  • sloc: ansic: 29,950; sh: 11,802; makefile: 679; python: 335; perl: 121; yacc: 93; lex: 50
file content (44 lines) | stat: -rw-r--r-- 1,376 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <logmath.h>

#include "test_macros.h"

#define LOG_EPSILON 1500

int
main(int argc, char *argv[])
{
	logmath_t *lmath;
	int32 rv;

	lmath = logmath_init(1.003, 0, 1);
	TEST_ASSERT(lmath);
	printf("log(1e-48) = %d\n", logmath_log(lmath, 1e-48));
	TEST_EQUAL_LOG(logmath_log(lmath, 1e-48), -36896);
	printf("exp(log(1e-48)) = %e\n",logmath_exp(lmath, -36896));
	TEST_EQUAL_FLOAT(logmath_exp(lmath, -36896), 1e-48);
	printf("log(42) = %d\n", logmath_log(lmath, 42));
	TEST_EQUAL_LOG(logmath_log(lmath, 42), 1247);
	printf("exp(log(42)) = %f\n",logmath_exp(lmath, 1247));
	TEST_EQUAL_FLOAT(logmath_exp(lmath, 1247), 41.9);
	TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
				   logmath_log(lmath, 5e-48)),
		       logmath_log(lmath, 6e-48));
	TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
				   logmath_log(lmath, 42)), 1247);

	rv = logmath_write(lmath, "tmp.logadd");
	TEST_EQUAL(rv, 0);
	logmath_free(lmath);
	lmath = logmath_read("tmp.logadd");
	TEST_ASSERT(lmath);
	TEST_EQUAL_LOG(logmath_log(lmath, 1e-48), -36896);
	TEST_EQUAL_LOG(logmath_log(lmath, 42), 1247);
	TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
				   logmath_log(lmath, 5e-48)),
		       logmath_log(lmath, 6e-48));
	TEST_EQUAL_LOG(logmath_add(lmath, logmath_log(lmath, 1e-48),
				   logmath_log(lmath, 42)), 1247);
	logmath_free(lmath);

	return 0;
}