File: test_log_int8.c

package info (click to toggle)
pocketsphinx 5.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,236 kB
  • sloc: ansic: 54,519; python: 2,438; sh: 566; cpp: 410; perl: 342; yacc: 93; lex: 50; makefile: 30
file content (47 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download
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
45
46
47
#include <pocketsphinx/logmath.h>

#include "test_macros.h"

#undef LOG_EPSILON
#define LOG_EPSILON 1500

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

	(void)argc;
	(void)argv;
	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;
}