diff options
author | Timothy B. Terriberry <tterribe@xiph.org> | 2012-08-06 21:01:27 +0400 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2012-08-06 21:08:11 +0400 |
commit | 02f19c26f17e43f3b8ac6cfe15a3d8a622f8ef07 (patch) | |
tree | 00d1661a81e98a5039fdff4a890bb395a3381c68 | |
parent | 0d57a5dc28c904ad765fea12f8ab40e3bd6f05f4 (diff) |
Fix fixed-point testilog2.
Use exact integer operations to confirm the value returned is the
correct one.
-rw-r--r-- | celt/tests/test_unit_mathops.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/celt/tests/test_unit_mathops.c b/celt/tests/test_unit_mathops.c index 8119bc1e..9673de6c 100644 --- a/celt/tests/test_unit_mathops.c +++ b/celt/tests/test_unit_mathops.c @@ -209,10 +209,17 @@ void testilog2(void) opus_val32 x; for (x=1;x<=268435455;x+=127) { - opus_val32 error = abs(celt_ilog2(x)-(int)floor(log2(x))); - if (error!=0) + opus_val32 lg = celt_ilog2(x); + if (lg<0 || lg>=31) { - printf("celt_ilog2 failed: celt_ilog2(x)!=floor(log2(x)) (x = %d, error = %d)\n",x,error); + printf("celt_ilog2 failed: 0<=celt_ilog2(x)<31 (x = %d, celt_ilog2(x) = %d)\n",x,lg); + ret = 1; + } + opus_val32 y = 1<<lg; + + if (x<y || (x>>1)>=y) + { + printf("celt_ilog2 failed: 2**celt_ilog2(x)<=x<2**(celt_ilog2(x)+1) (x = %d, 2**celt_ilog2(x) = %d)\n",x,y); ret = 1; } } |