summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorWincent Balin <wincent@rockbox.org>2009-07-29 21:35:38 +0000
committerWincent Balin <wincent@rockbox.org>2009-07-29 21:35:38 +0000
commitf95dc688cfbea5b3355bee0436767a8add8602d2 (patch)
tree360093b6f8b69077adaa7f8a621c8a10b9bc4570 /apps
parent2fb73842a9b51e554a3a14feb0b4c0814c82ebec (diff)
downloadrockbox-f95dc688cfbea5b3355bee0436767a8add8602d2.tar.gz
rockbox-f95dc688cfbea5b3355bee0436767a8add8602d2.zip
Minor additions to floating point math functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22086 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/pdbox/pdbox-func.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/apps/plugins/pdbox/pdbox-func.c b/apps/plugins/pdbox/pdbox-func.c
index c5e81ed7b9..22c8714b3f 100644
--- a/apps/plugins/pdbox/pdbox-func.c
+++ b/apps/plugins/pdbox/pdbox-func.c
@@ -333,11 +333,19 @@ long rb_atol(const char* str)
333 333
334float rb_sin(float rad) 334float rb_sin(float rad)
335{ 335{
336 int cycles;
337
336 /* Trim input value to -PI..PI interval. */ 338 /* Trim input value to -PI..PI interval. */
337 if(rad < -3.14159265) 339 if(rad > 3.14159265)
338 rad += 6.28318531; 340 {
339 else if(rad > 3.14159265) 341 cycles = rad / 6.28318531;
340 rad -= 6.28318531; 342 rad -= (6.28318531 * (float) cycles);
343 }
344 else if(rad < -3.14159265)
345 {
346 cycles = rad / -6.28318531;
347 rad += (6.28318531 * (float) cycles);
348 }
341 349
342 if(rad < 0) 350 if(rad < 0)
343 return (1.27323954 * rad + 0.405284735 * rad * rad); 351 return (1.27323954 * rad + 0.405284735 * rad * rad);
@@ -348,11 +356,7 @@ float rb_sin(float rad)
348float rb_cos(float rad) 356float rb_cos(float rad)
349{ 357{
350 /* Compute cosine: sin(x + PI/2) = cos(x) */ 358 /* Compute cosine: sin(x + PI/2) = cos(x) */
351 rad += 1.57079632; 359 return rb_sin(rad + 1.57079632);
352 if(rad > 3.14159265)
353 rad -= 6.28318531;
354
355 return rb_sin(rad);
356} 360}
357 361
358 362
@@ -2108,54 +2112,39 @@ union ieee754_double
2108 /* This is the IEEE 754 double-precision format. */ 2112 /* This is the IEEE 754 double-precision format. */
2109 struct 2113 struct
2110 { 2114 {
2111#if defined(ROCKBOX_BIG_ENDIAN) 2115#ifdef ROCKBOX_BIG_ENDIAN
2112 unsigned int negative:1; 2116 unsigned int negative:1;
2113 unsigned int exponent:11; 2117 unsigned int exponent:11;
2114 /* Together these comprise the mantissa. */ 2118 /* Together these comprise the mantissa. */
2115 unsigned int mantissa0:20; 2119 unsigned int mantissa0:20;
2116 unsigned int mantissa1:32; 2120 unsigned int mantissa1:32;
2117#else 2121#else /* ROCKBOX_LITTLE_ENDIAN */
2118# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
2119 unsigned int mantissa0:20;
2120 unsigned int exponent:11;
2121 unsigned int negative:1;
2122 unsigned int mantissa1:32;
2123# else
2124 /* Together these comprise the mantissa. */ 2122 /* Together these comprise the mantissa. */
2125 unsigned int mantissa1:32; 2123 unsigned int mantissa1:32;
2126 unsigned int mantissa0:20; 2124 unsigned int mantissa0:20;
2127 unsigned int exponent:11; 2125 unsigned int exponent:11;
2128 unsigned int negative:1; 2126 unsigned int negative:1;
2129# endif 2127#endif /* ROCKBOX_LITTLE_ENDIAN */
2130#endif /* Little endian. */
2131 } ieee; 2128 } ieee;
2132 2129
2133 /* This format makes it easier to see if a NaN is a signalling NaN. */ 2130 /* This format makes it easier to see if a NaN is a signalling NaN. */
2134 struct 2131 struct
2135 { 2132 {
2136#if defined(ROCKBOX_BIG_ENDIAN) 2133#ifdef ROCKBOX_BIG_ENDIAN
2137 unsigned int negative:1; 2134 unsigned int negative:1;
2138 unsigned int exponent:11; 2135 unsigned int exponent:11;
2139 unsigned int quiet_nan:1; 2136 unsigned int quiet_nan:1;
2140 /* Together these comprise the mantissa. */ 2137 /* Together these comprise the mantissa. */
2141 unsigned int mantissa0:19; 2138 unsigned int mantissa0:19;
2142 unsigned int mantissa1:32; 2139 unsigned int mantissa1:32;
2143#else 2140#else /* ROCKBOX_LITTLE_ENDIAN */
2144# if __FLOAT_WORD_ORDER == __BIG_ENDIAN
2145 unsigned int mantissa0:19;
2146 unsigned int quiet_nan:1;
2147 unsigned int exponent:11;
2148 unsigned int negative:1;
2149 unsigned int mantissa1:32;
2150# else
2151 /* Together these comprise the mantissa. */ 2141 /* Together these comprise the mantissa. */
2152 unsigned int mantissa1:32; 2142 unsigned int mantissa1:32;
2153 unsigned int mantissa0:19; 2143 unsigned int mantissa0:19;
2154 unsigned int quiet_nan:1; 2144 unsigned int quiet_nan:1;
2155 unsigned int exponent:11; 2145 unsigned int exponent:11;
2156 unsigned int negative:1; 2146 unsigned int negative:1;
2157# endif 2147#endif /* ROCKBOX_LITTLE_ENDIAN */
2158#endif
2159 } ieee_nan; 2148 } ieee_nan;
2160 }; 2149 };
2161 2150