Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Mark Harris
Opus
Commits
b92dce32
Commit
b92dce32
authored
Jun 28, 2009
by
Gregory Maxwell
Browse files
Additional mathops.h tests.
parent
8d2c51af
Changes
2
Hide whitespace changes
Inline
Side-by-side
libcelt/mathops.h
View file @
b92dce32
...
...
@@ -155,8 +155,8 @@ static inline float celt_exp2(float x)
}
#else
#define celt_log2(x) (1.442695*log(x))
#define celt_exp2(x) (exp(0.6931
5
*(x)))
#define celt_log2(x) (1.442695
040888963387
*log(x))
#define celt_exp2(x) (exp(0.6931
471805599453094
*(x)))
#endif
#endif
...
...
tests/mathops-test.c
View file @
b92dce32
...
...
@@ -71,10 +71,75 @@ void testrsqrt(void)
}
}
#ifndef FIXED_POINT
void
testlog2
(
void
)
{
float
x
;
for
(
x
=
0
.
001
;
x
<
1677700
.
0
;
x
+=
(
x
/
8
.
0
))
{
float
error
=
fabs
((
1
.
442695040888963387
*
log
(
x
))
-
celt_log2
(
x
));
if
(
error
>
0
.
001
)
{
fprintf
(
stderr
,
"celt_log2 failed: fabs((1.442695040888963387*log(x))-celt_log2(x))>0.001 (x = %f, error = %f)
\n
"
,
x
,
error
);
ret
=
1
;
}
}
}
void
testexp2
(
void
)
{
float
x
;
for
(
x
=-
11
.
0
;
x
<
24
.
0
;
x
+=
0
.
0007
)
{
float
error
=
fabs
(
x
-
(
1
.
442695040888963387
*
log
(
celt_exp2
(
x
))));
if
(
error
>
0
.
0005
)
{
fprintf
(
stderr
,
"celt_exp2 failed: fabs(x-(1.442695040888963387*log(celt_exp2(x))))>0.0005 (x = %f, error = %f)
\n
"
,
x
,
error
);
ret
=
1
;
}
}
}
void
testexp2log2
(
void
)
{
float
x
;
for
(
x
=-
11
.
0
;
x
<
24
.
0
;
x
+=
0
.
0007
)
{
float
error
=
fabs
(
x
-
(
celt_log2
(
celt_exp2
(
x
))));
if
(
error
>
0
.
001
)
{
fprintf
(
stderr
,
"celt_log2/celt_exp2 failed: fabs(x-(celt_log2(celt_exp2(x))))>0.001 (x = %f, error = %f)
\n
"
,
x
,
error
);
ret
=
1
;
}
}
}
#else
void
testilog2
(
void
)
{
celt_word32_t
x
;
for
(
x
=
1
;
x
<=
268435455
;
x
+=
127
)
{
celt_word32_t
error
=
abs
(
celt_ilog2
(
x
)
-
(
int
)
floor
(
log2
(
x
)));
if
(
error
!=
0
)
{
printf
(
"celt_ilog2 failed: celt_ilog2(x)!=floor(log2(x)) (x = %d, error = %d)
\n
"
,
x
,
error
);
ret
=
1
;
}
}
}
#endif
int
main
(
void
)
{
testdiv
();
testsqrt
();
testrsqrt
();
#ifndef FIXED_POINT
testlog2
();
testexp2
();
testexp2log2
();
#else
testilog2
();
#endif
return
ret
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment