summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/rbwrappers.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-01-04 20:31:06 -0500
committerFranklin Wei <git@fwei.tk>2017-01-04 20:36:04 -0500
commit31907283a4bb3aaa69a5b9cc1c1606271fb58660 (patch)
treea3a94baac3a95c0e0d257a827fdecb1ffc33033b /apps/plugins/puzzles/rbwrappers.c
parentad2297d353412dd20fc439b8053b25b18872069c (diff)
downloadrockbox-31907283a4bb3aaa69a5b9cc1c1606271fb58660.tar.gz
rockbox-31907283a4bb3aaa69a5b9cc1c1606271fb58660.zip
puzzles: fix a few things
- old acos() function was broken, replaced with a call to atan2(); this fixes "Cube!" - Makefile extended to support building "unfinished games", but not enabled - a backdrop issue fixed in rockbox.c Change-Id: I9393e958d43de32f4ccf18e1cb409f75c2e1ed3c
Diffstat (limited to 'apps/plugins/puzzles/rbwrappers.c')
-rw-r--r--apps/plugins/puzzles/rbwrappers.c95
1 files changed, 2 insertions, 93 deletions
diff --git a/apps/plugins/puzzles/rbwrappers.c b/apps/plugins/puzzles/rbwrappers.c
index b553a66dfc..2762194de3 100644
--- a/apps/plugins/puzzles/rbwrappers.c
+++ b/apps/plugins/puzzles/rbwrappers.c
@@ -1013,101 +1013,10 @@ float sqrt_wrapper(float x)
1013 return z; 1013 return z;
1014} 1014}
1015 1015
1016/* @(#)e_acos.c 1.3 95/01/18 */ 1016/* hack, simple trig */
1017/*
1018 * ====================================================
1019 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1020 *
1021 * Developed at SunSoft, a Sun Microsystems, Inc. business.
1022 * Permission to use, copy, modify, and distribute this
1023 * software is freely granted, provided that this notice
1024 * is preserved.
1025 * ====================================================
1026 */
1027
1028/* __ieee754_acos(x)
1029 * Method :
1030 * acos(x) = pi/2 - asin(x)
1031 * acos(-x) = pi/2 + asin(x)
1032 * For |x|<=0.5
1033 * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
1034 * For x>0.5
1035 * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
1036 * = 2asin(sqrt((1-x)/2))
1037 * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
1038 * = 2f + (2c + 2s*z*R(z))
1039 * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
1040 * for f so that f+c ~ sqrt(z).
1041 * For x<-0.5
1042 * acos(x) = pi - 2asin(sqrt((1-|x|)/2))
1043 * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
1044 *
1045 * Special cases:
1046 * if x is NaN, return x itself;
1047 * if |x|>1, return NaN with invalid signal.
1048 *
1049 * Function needed: sqrt
1050 */
1051
1052#ifdef __STDC__
1053static const double
1054#else
1055static double
1056#endif
1057pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
1058pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
1059pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
1060pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
1061pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
1062pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
1063pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
1064pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
1065qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
1066qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
1067qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
1068qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
1069
1070double acos_wrapper(double x) 1017double acos_wrapper(double x)
1071{ 1018{
1072 double z,p,q,r,w,s,c,df; 1019 return atan2_wrapper(sqrt_wrapper(1.0 - x * x), x);
1073 int hx,ix;
1074 hx = __HI(x);
1075 ix = hx&0x7fffffff;
1076 if(ix>=0x3ff00000) { /* |x| >= 1 */
1077 if(((ix-0x3ff00000)|__LO(x))==0) { /* |x|==1 */
1078 if(hx>0) return 0.0; /* acos(1) = 0 */
1079 else return pi+2.0*pio2_lo; /* acos(-1)= pi */
1080 }
1081 return (x-x)/(x-x); /* acos(|x|>1) is NaN */
1082 }
1083 if(ix<0x3fe00000) { /* |x| < 0.5 */
1084 if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
1085 z = x*x;
1086 p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
1087 q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
1088 r = p/q;
1089 return pio2_hi - (x - (pio2_lo-x*r));
1090 } else if (hx<0) { /* x < -0.5 */
1091 z = (one+x)*0.5;
1092 p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
1093 q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
1094 s = sqrt_wrapper(z);
1095 r = p/q;
1096 w = r*s-pio2_lo;
1097 return pi - 2.0*(s+w);
1098 } else { /* x > 0.5 */
1099 z = (one-x)*0.5;
1100 s = sqrt_wrapper(z);
1101 df = s;
1102 __LO(df) = 0;
1103 c = (z-df*df)/(s+df);
1104 p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
1105 q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
1106 r = p/q;
1107 w = r*s+c;
1108 return 2.0*(df+w);
1109 }
1110
1111} 1020}
1112 1021
1113/* 1022/*