summaryrefslogtreecommitdiff
path: root/fixpow.c
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2014-10-07 15:53:27 +0200
committererdgeist <erdgeist@erdgeist.org>2014-10-07 15:53:27 +0200
commitf53202b53f9c8d1294219ec67d3a298fd59f2bef (patch)
tree2f64efccedab641f3af9f88aa2f4fda692f8b6ab /fixpow.c
parentda540be956937b49beba8e02569f16b80561c5a8 (diff)
Add test code to check reliablity of fixexp(), for sufficently large absolute values (>0.00013) our error is below 0.2%)HEADmaster
Diffstat (limited to 'fixpow.c')
-rw-r--r--fixpow.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fixpow.c b/fixpow.c
index 3db6df3..a023f7a 100644
--- a/fixpow.c
+++ b/fixpow.c
@@ -256,10 +256,16 @@ int main()
256 256
257 // Testing fixexp 257 // Testing fixexp
258 for (input=-2147483648; input < TO_Q26(10.39720770839918); ++input ) { 258 for (input=-2147483648; input < TO_Q26(10.39720770839918); ++input ) {
259 int32_t expected = TO_Q16(exp(FROM_Q26(input))); 259 double expected = exp(FROM_Q26(input));
260 int32_t output = fixexp(input); 260 int32_t expected_int = TO_Q16(expected);
261 if( abs(output-expected) > 16 ) 261 int32_t output_int = fixexp(input);
262 printf( "%08X : %08X = %08X (%08d)\n", output, expected, abs(output-expected), input ); 262 double output = FROM_Q16(output_int);
263 if( abs(output_int-expected_int) > 8 ) {
264 if( expected > output && output > 0 && expected / output > 1.002 )
265 printf( "%08X : %08X = %08X (%08d)\n", output_int, expected_int, abs(output_int-expected_int), input );
266 if( expected < output && expected > 0 && output / expected > 1.002 )
267 printf( "%08X : %08X = %08X (%08d)\n", output_int, expected_int, abs(output_int-expected_int), input );
268 }
263 } 269 }
264 270
265 printf( "pow(%lf,%lf)=%lf (%s)\n", base, exponent, FROM_Q16(result), error?"ERROR":"OK" ); 271 printf( "pow(%lf,%lf)=%lf (%s)\n", base, exponent, FROM_Q16(result), error?"ERROR":"OK" );