A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add arcsin, arccos and arctan to calculator

Change-Id: I9aaded58718ae410239678abe6cf6196286bc7f8

+123 -2
+122 -2
apps/plugins/calculator.c
··· 1028 1028 1029 1029 /* ----------------------------------------------------------------------- 1030 1030 transcendFunc uses CORDIC (COordinate Rotation DIgital Computer) method 1031 - transcendFunc can do sin,cos,log,exp 1031 + transcendFunc can do sin,cos,log,exp,asin,acos,atan 1032 1032 input parameter is angle 1033 1033 ----------------------------------------------------------------------- */ 1034 1034 static void transcendFunc(char* func, double* tt, int* ttPower) 1035 1035 { 1036 - double t = (*tt)*M_PI/180; int tPower = *ttPower; 1036 + double t = (*tt); 1037 + int tPower = *ttPower; 1037 1038 int sign = 1; 1038 1039 int n = 50; /* n <=50, tables are all <= 50 */ 1039 1040 int j; ··· 1050 1051 *ttPower = 0; 1051 1052 calStatus = cal_normal; 1052 1053 1054 + /* Powerscale */ 1055 + while (tPower > 0){ 1056 + t *= 10; 1057 + tPower--; 1058 + } 1059 + while (tPower < 0) { 1060 + t /= 10; 1061 + tPower++; 1062 + } 1063 + 1064 + /* Vectoring mode */ 1065 + if(func[0] == 'a' || func[0] == 'A') { 1066 + if(func[1] == 's' || func[1] == 'S') { /* arcsin */ 1067 + /* arcsin input must be in [-1, 1] */ 1068 + if(t < -1.0 || t > 1.0) { 1069 + calStatus = cal_error; 1070 + return; 1071 + } 1072 + /* Avoid division by zero */ 1073 + if(t == 1.0) { 1074 + *tt = 90.0; /* arcsin(1) = 90° */ 1075 + return; 1076 + } 1077 + if(t == -1.0) { 1078 + *tt = -90.0; /* arcsin(-1) = -90° */ 1079 + return; 1080 + } 1081 + 1082 + /* Vectoring mode */ 1083 + /* Start with vector (sqrt(1-t^2), t) and find its angle */ 1084 + double magnitude = mySqrt(1.0 - t*t); 1085 + x = magnitude; 1086 + y = t; 1087 + z = 0.0; 1088 + 1089 + /* Vectoring mode: drive y to 0 */ 1090 + for (j = 1; j < n + 2; j++) { 1091 + if(y >= 0) { 1092 + /* Rotate clockwise (negative direction) */ 1093 + xt = x + y * cordicTable[j-1][0]; 1094 + yt = y - x * cordicTable[j-1][0]; 1095 + zt = z - cordicTable[j-1][1]; 1096 + } else { 1097 + /* Rotate anticlockwise (positive direction) */ 1098 + xt = x - y * cordicTable[j-1][0]; 1099 + yt = y + x * cordicTable[j-1][0]; 1100 + zt = z + cordicTable[j-1][1]; 1101 + } 1102 + x = xt; 1103 + y = yt; 1104 + z = zt; 1105 + } 1106 + *tt = z * 180/M_PI * -1; /* Convert to degrees and invert sign */ 1107 + return; 1108 + } 1109 + else if(func[1] == 'c' || func[1] == 'C') { /* arccos */ 1110 + /* arccos input must be in [-1, 1] */ 1111 + if(t < -1.0 || t > 1.0) { 1112 + calStatus = cal_error; 1113 + return; 1114 + } 1115 + /* For arccos: use arcsin relationship: arccos(t) = π/2 - arcsin(t) */ 1116 + double arcsin_input = t; 1117 + int arcsin_power = 0; 1118 + 1119 + /* Save current function context */ 1120 + char original_func[3]; 1121 + strncpy(original_func, func, 3); 1122 + 1123 + transcendFunc("asin", &arcsin_input, &arcsin_power); 1124 + 1125 + if (calStatus == cal_error) { 1126 + return; 1127 + } 1128 + 1129 + /* arccos(t) = 90° - arcsin(t) */ 1130 + /* arcsin_input now contains arcsin(t) in degrees */ 1131 + double arccos_degrees = 90.0 - arcsin_input; 1132 + *tt = arccos_degrees; 1133 + return; 1134 + } 1135 + else if(func[1] == 't' || func[1] == 'T') { /* arctan */ 1136 + /* start with x=1, y=input, z=0 and drive y to 0 */ 1137 + x = 1.0; 1138 + y = t; 1139 + z = 0.0; 1140 + 1141 + /* Vectoring mode: drive y to 0 */ 1142 + for (j=1; j<n+2; j++){ 1143 + if(y < 0) { 1144 + /* Rotate anticlockwise */ 1145 + xt = x - y*cordicTable[j-1][0]; 1146 + yt = y + x*cordicTable[j-1][0]; 1147 + zt = z + cordicTable[j-1][1]; 1148 + } else { 1149 + /* Rotate clockwise */ 1150 + xt = x + y*cordicTable[j-1][0]; 1151 + yt = y - x*cordicTable[j-1][0]; 1152 + zt = z - cordicTable[j-1][1]; 1153 + } 1154 + x = xt; y = yt; z = zt; 1155 + } 1156 + *tt = z * 180/M_PI * -1; /* Convert back to degrees and invert sign */ 1157 + return; 1158 + } 1159 + } 1160 + 1053 1161 if( func[0] =='s' || func[0] =='S'|| func[0] =='t' || func[0] =='T') 1054 1162 sign = SIGN(t); 1055 1163 else { ··· 1057 1165 sign = 1; 1058 1166 } 1059 1167 t = ABS(t); 1168 + 1169 + /* Jump to radians for rotation mode */ 1170 + t = t * M_PI / 180; 1060 1171 1061 1172 while (tPower > 0){ 1062 1173 t *= 10; ··· 1289 1400 break; 1290 1401 case sci_tan: 1291 1402 transcendFunc("tan", &result, &power); 1403 + break; 1404 + case sci_asin: 1405 + transcendFunc("asin", &result, &power); 1406 + break; 1407 + case sci_acos: 1408 + transcendFunc("acos", &result, &power); 1409 + break; 1410 + case sci_atan: 1411 + transcendFunc("atan", &result, &power); 1292 1412 break; 1293 1413 case sci_fac: 1294 1414 if (power<0 || power>8 || result<0 )
+1
docs/CREDITS
··· 743 743 Yannic Schmidt 744 744 Hairo R. Carela 745 745 Sergio Delgado 746 + Cameron John Peck 746 747 747 748 The libmad team 748 749 The wavpack team