diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/x_arithmetic.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip |
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/x_arithmetic.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/x_arithmetic.c | 897 |
1 files changed, 0 insertions, 897 deletions
diff --git a/apps/plugins/pdbox/PDa/src/x_arithmetic.c b/apps/plugins/pdbox/PDa/src/x_arithmetic.c index ad309f7a68..f060f2fd49 100644 --- a/apps/plugins/pdbox/PDa/src/x_arithmetic.c +++ b/apps/plugins/pdbox/PDa/src/x_arithmetic.c | |||
@@ -893,900 +893,3 @@ void x_arithmetic_setup(void) | |||
893 | clip_setup(); | 893 | clip_setup(); |
894 | } | 894 | } |
895 | 895 | ||
896 | |||
897 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
898 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
899 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
900 | |||
901 | /* arithmetic: binops ala C language. The 4 functions and relationals are | ||
902 | done on floats; the logical and bitwise binops convert their | ||
903 | inputs to int and their outputs back to float. */ | ||
904 | |||
905 | #include "m_pd.h" | ||
906 | #include <math.h> | ||
907 | |||
908 | |||
909 | /* MSW and OSX don't appear to have single-precision ANSI math */ | ||
910 | |||
911 | #define sinf sin | ||
912 | #define cosf cos | ||
913 | #define atanf atan | ||
914 | #define atan2f atan2 | ||
915 | #define sqrtf sqrt | ||
916 | #define logf log | ||
917 | #define expf exp | ||
918 | #define fabsf fabs | ||
919 | #define powf pow | ||
920 | |||
921 | |||
922 | typedef struct _binop | ||
923 | { | ||
924 | t_object x_obj; | ||
925 | t_float x_f1; | ||
926 | t_float x_f2; | ||
927 | } t_binop; | ||
928 | |||
929 | /* ------------------ binop1: +, -, *, / ----------------------------- */ | ||
930 | |||
931 | static void *binop1_new(t_class *floatclass, t_floatarg f) | ||
932 | { | ||
933 | t_binop *x = (t_binop *)pd_new(floatclass); | ||
934 | outlet_new(&x->x_obj, &s_float); | ||
935 | floatinlet_new(&x->x_obj, &x->x_f2); | ||
936 | x->x_f1 = 0; | ||
937 | x->x_f2 = f; | ||
938 | return (x); | ||
939 | } | ||
940 | |||
941 | /* --------------------- addition ------------------------------- */ | ||
942 | |||
943 | static t_class *binop1_plus_class; | ||
944 | |||
945 | static void *binop1_plus_new(t_floatarg f) | ||
946 | { | ||
947 | return (binop1_new(binop1_plus_class, f)); | ||
948 | } | ||
949 | |||
950 | static void binop1_plus_bang(t_binop *x) | ||
951 | { | ||
952 | outlet_float(x->x_obj.ob_outlet, x->x_f1 + x->x_f2); | ||
953 | } | ||
954 | |||
955 | static void binop1_plus_float(t_binop *x, t_float f) | ||
956 | { | ||
957 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) + x->x_f2); | ||
958 | } | ||
959 | |||
960 | /* --------------------- subtraction ------------------------------- */ | ||
961 | |||
962 | static t_class *binop1_minus_class; | ||
963 | |||
964 | static void *binop1_minus_new(t_floatarg f) | ||
965 | { | ||
966 | return (binop1_new(binop1_minus_class, f)); | ||
967 | } | ||
968 | |||
969 | static void binop1_minus_bang(t_binop *x) | ||
970 | { | ||
971 | outlet_float(x->x_obj.ob_outlet, x->x_f1 - x->x_f2); | ||
972 | } | ||
973 | |||
974 | static void binop1_minus_float(t_binop *x, t_float f) | ||
975 | { | ||
976 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) - x->x_f2); | ||
977 | } | ||
978 | |||
979 | /* --------------------- multiplication ------------------------------- */ | ||
980 | |||
981 | static t_class *binop1_times_class; | ||
982 | |||
983 | static void *binop1_times_new(t_floatarg f) | ||
984 | { | ||
985 | return (binop1_new(binop1_times_class, f)); | ||
986 | } | ||
987 | |||
988 | static void binop1_times_bang(t_binop *x) | ||
989 | { | ||
990 | outlet_float(x->x_obj.ob_outlet, x->x_f1 * x->x_f2); | ||
991 | } | ||
992 | |||
993 | static void binop1_times_float(t_binop *x, t_float f) | ||
994 | { | ||
995 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) * x->x_f2); | ||
996 | } | ||
997 | |||
998 | /* --------------------- division ------------------------------- */ | ||
999 | |||
1000 | static t_class *binop1_div_class; | ||
1001 | |||
1002 | static void *binop1_div_new(t_floatarg f) | ||
1003 | { | ||
1004 | return (binop1_new(binop1_div_class, f)); | ||
1005 | } | ||
1006 | |||
1007 | static void binop1_div_bang(t_binop *x) | ||
1008 | { | ||
1009 | outlet_float(x->x_obj.ob_outlet, | ||
1010 | (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0)); | ||
1011 | } | ||
1012 | |||
1013 | static void binop1_div_float(t_binop *x, t_float f) | ||
1014 | { | ||
1015 | x->x_f1 = f; | ||
1016 | outlet_float(x->x_obj.ob_outlet, | ||
1017 | (x->x_f2 != 0 ? x->x_f1 / x->x_f2 : 0)); | ||
1018 | } | ||
1019 | |||
1020 | /* ------------------------ pow -------------------------------- */ | ||
1021 | |||
1022 | static t_class *binop1_pow_class; | ||
1023 | |||
1024 | static void *binop1_pow_new(t_floatarg f) | ||
1025 | { | ||
1026 | return (binop1_new(binop1_pow_class, f)); | ||
1027 | } | ||
1028 | |||
1029 | static void binop1_pow_bang(t_binop *x) | ||
1030 | { | ||
1031 | outlet_float(x->x_obj.ob_outlet, | ||
1032 | (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0)); | ||
1033 | } | ||
1034 | |||
1035 | static void binop1_pow_float(t_binop *x, t_float f) | ||
1036 | { | ||
1037 | x->x_f1 = f; | ||
1038 | outlet_float(x->x_obj.ob_outlet, | ||
1039 | (x->x_f1 > 0 ? powf(x->x_f1, x->x_f2) : 0)); | ||
1040 | } | ||
1041 | |||
1042 | /* ------------------------ max -------------------------------- */ | ||
1043 | |||
1044 | static t_class *binop1_max_class; | ||
1045 | |||
1046 | static void *binop1_max_new(t_floatarg f) | ||
1047 | { | ||
1048 | return (binop1_new(binop1_max_class, f)); | ||
1049 | } | ||
1050 | |||
1051 | static void binop1_max_bang(t_binop *x) | ||
1052 | { | ||
1053 | outlet_float(x->x_obj.ob_outlet, | ||
1054 | (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2)); | ||
1055 | } | ||
1056 | |||
1057 | static void binop1_max_float(t_binop *x, t_float f) | ||
1058 | { | ||
1059 | x->x_f1 = f; | ||
1060 | outlet_float(x->x_obj.ob_outlet, | ||
1061 | (x->x_f1 > x->x_f2 ? x->x_f1 : x->x_f2)); | ||
1062 | } | ||
1063 | |||
1064 | /* ------------------------ min -------------------------------- */ | ||
1065 | |||
1066 | static t_class *binop1_min_class; | ||
1067 | |||
1068 | static void *binop1_min_new(t_floatarg f) | ||
1069 | { | ||
1070 | return (binop1_new(binop1_min_class, f)); | ||
1071 | } | ||
1072 | |||
1073 | static void binop1_min_bang(t_binop *x) | ||
1074 | { | ||
1075 | outlet_float(x->x_obj.ob_outlet, | ||
1076 | (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2)); | ||
1077 | } | ||
1078 | |||
1079 | static void binop1_min_float(t_binop *x, t_float f) | ||
1080 | { | ||
1081 | x->x_f1 = f; | ||
1082 | outlet_float(x->x_obj.ob_outlet, | ||
1083 | (x->x_f1 < x->x_f2 ? x->x_f1 : x->x_f2)); | ||
1084 | } | ||
1085 | |||
1086 | /* ------------------ binop2: ==, !=, >, <, >=, <=. -------------------- */ | ||
1087 | |||
1088 | static void *binop2_new(t_class *floatclass, t_floatarg f) | ||
1089 | { | ||
1090 | t_binop *x = (t_binop *)pd_new(floatclass); | ||
1091 | outlet_new(&x->x_obj, &s_float); | ||
1092 | floatinlet_new(&x->x_obj, &x->x_f2); | ||
1093 | x->x_f1 = 0; | ||
1094 | x->x_f2 = f; | ||
1095 | return (x); | ||
1096 | } | ||
1097 | |||
1098 | /* --------------------- == ------------------------------- */ | ||
1099 | |||
1100 | static t_class *binop2_ee_class; | ||
1101 | |||
1102 | static void *binop2_ee_new(t_floatarg f) | ||
1103 | { | ||
1104 | return (binop2_new(binop2_ee_class, f)); | ||
1105 | } | ||
1106 | |||
1107 | static void binop2_ee_bang(t_binop *x) | ||
1108 | { | ||
1109 | outlet_float(x->x_obj.ob_outlet, x->x_f1 == x->x_f2); | ||
1110 | } | ||
1111 | |||
1112 | static void binop2_ee_float(t_binop *x, t_float f) | ||
1113 | { | ||
1114 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) == x->x_f2); | ||
1115 | } | ||
1116 | |||
1117 | /* --------------------- != ------------------------------- */ | ||
1118 | |||
1119 | static t_class *binop2_ne_class; | ||
1120 | |||
1121 | static void *binop2_ne_new(t_floatarg f) | ||
1122 | { | ||
1123 | return (binop2_new(binop2_ne_class, f)); | ||
1124 | } | ||
1125 | |||
1126 | static void binop2_ne_bang(t_binop *x) | ||
1127 | { | ||
1128 | outlet_float(x->x_obj.ob_outlet, x->x_f1 != x->x_f2); | ||
1129 | } | ||
1130 | |||
1131 | static void binop2_ne_float(t_binop *x, t_float f) | ||
1132 | { | ||
1133 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) != x->x_f2); | ||
1134 | } | ||
1135 | |||
1136 | /* --------------------- > ------------------------------- */ | ||
1137 | |||
1138 | static t_class *binop2_gt_class; | ||
1139 | |||
1140 | static void *binop2_gt_new(t_floatarg f) | ||
1141 | { | ||
1142 | return (binop2_new(binop2_gt_class, f)); | ||
1143 | } | ||
1144 | |||
1145 | static void binop2_gt_bang(t_binop *x) | ||
1146 | { | ||
1147 | outlet_float(x->x_obj.ob_outlet, x->x_f1 > x->x_f2); | ||
1148 | } | ||
1149 | |||
1150 | static void binop2_gt_float(t_binop *x, t_float f) | ||
1151 | { | ||
1152 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) > x->x_f2); | ||
1153 | } | ||
1154 | |||
1155 | /* --------------------- < ------------------------------- */ | ||
1156 | |||
1157 | static t_class *binop2_lt_class; | ||
1158 | |||
1159 | static void *binop2_lt_new(t_floatarg f) | ||
1160 | { | ||
1161 | return (binop2_new(binop2_lt_class, f)); | ||
1162 | } | ||
1163 | |||
1164 | static void binop2_lt_bang(t_binop *x) | ||
1165 | { | ||
1166 | outlet_float(x->x_obj.ob_outlet, x->x_f1 < x->x_f2); | ||
1167 | } | ||
1168 | |||
1169 | static void binop2_lt_float(t_binop *x, t_float f) | ||
1170 | { | ||
1171 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) < x->x_f2); | ||
1172 | } | ||
1173 | |||
1174 | /* --------------------- >= ------------------------------- */ | ||
1175 | |||
1176 | static t_class *binop2_ge_class; | ||
1177 | |||
1178 | static void *binop2_ge_new(t_floatarg f) | ||
1179 | { | ||
1180 | return (binop2_new(binop2_ge_class, f)); | ||
1181 | } | ||
1182 | |||
1183 | static void binop2_ge_bang(t_binop *x) | ||
1184 | { | ||
1185 | outlet_float(x->x_obj.ob_outlet, x->x_f1 >= x->x_f2); | ||
1186 | } | ||
1187 | |||
1188 | static void binop2_ge_float(t_binop *x, t_float f) | ||
1189 | { | ||
1190 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) >= x->x_f2); | ||
1191 | } | ||
1192 | |||
1193 | /* --------------------- <= ------------------------------- */ | ||
1194 | |||
1195 | static t_class *binop2_le_class; | ||
1196 | |||
1197 | static void *binop2_le_new(t_floatarg f) | ||
1198 | { | ||
1199 | return (binop2_new(binop2_le_class, f)); | ||
1200 | } | ||
1201 | |||
1202 | static void binop2_le_bang(t_binop *x) | ||
1203 | { | ||
1204 | outlet_float(x->x_obj.ob_outlet, x->x_f1 <= x->x_f2); | ||
1205 | } | ||
1206 | |||
1207 | static void binop2_le_float(t_binop *x, t_float f) | ||
1208 | { | ||
1209 | outlet_float(x->x_obj.ob_outlet, (x->x_f1 = f) <= x->x_f2); | ||
1210 | } | ||
1211 | |||
1212 | /* ------------- binop3: &, |, &&, ||, <<, >>, %, mod, div ------------------ */ | ||
1213 | |||
1214 | static void *binop3_new(t_class *fixclass, t_floatarg f) | ||
1215 | { | ||
1216 | t_binop *x = (t_binop *)pd_new(fixclass); | ||
1217 | outlet_new(&x->x_obj, &s_float); | ||
1218 | floatinlet_new(&x->x_obj, &x->x_f2); | ||
1219 | x->x_f1 = 0; | ||
1220 | x->x_f2 = f; | ||
1221 | return (x); | ||
1222 | } | ||
1223 | |||
1224 | /* --------------------------- & ---------------------------- */ | ||
1225 | |||
1226 | static t_class *binop3_ba_class; | ||
1227 | |||
1228 | static void *binop3_ba_new(t_floatarg f) | ||
1229 | { | ||
1230 | return (binop3_new(binop3_ba_class, f)); | ||
1231 | } | ||
1232 | |||
1233 | static void binop2_ba_bang(t_binop *x) | ||
1234 | { | ||
1235 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) & (int)(x->x_f2)); | ||
1236 | } | ||
1237 | |||
1238 | static void binop2_ba_float(t_binop *x, t_float f) | ||
1239 | { | ||
1240 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) & (int)(x->x_f2)); | ||
1241 | } | ||
1242 | |||
1243 | /* --------------------------- && ---------------------------- */ | ||
1244 | |||
1245 | static t_class *binop3_la_class; | ||
1246 | |||
1247 | static void *binop3_la_new(t_floatarg f) | ||
1248 | { | ||
1249 | return (binop3_new(binop3_la_class, f)); | ||
1250 | } | ||
1251 | |||
1252 | static void binop2_la_bang(t_binop *x) | ||
1253 | { | ||
1254 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) && (int)(x->x_f2)); | ||
1255 | } | ||
1256 | |||
1257 | static void binop2_la_float(t_binop *x, t_float f) | ||
1258 | { | ||
1259 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) && (int)(x->x_f2)); | ||
1260 | } | ||
1261 | |||
1262 | /* --------------------------- | ---------------------------- */ | ||
1263 | |||
1264 | static t_class *binop3_bo_class; | ||
1265 | |||
1266 | static void *binop3_bo_new(t_floatarg f) | ||
1267 | { | ||
1268 | return (binop3_new(binop3_bo_class, f)); | ||
1269 | } | ||
1270 | |||
1271 | static void binop2_bo_bang(t_binop *x) | ||
1272 | { | ||
1273 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) | (int)(x->x_f2)); | ||
1274 | } | ||
1275 | |||
1276 | static void binop2_bo_float(t_binop *x, t_float f) | ||
1277 | { | ||
1278 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) | (int)(x->x_f2)); | ||
1279 | } | ||
1280 | |||
1281 | /* --------------------------- || ---------------------------- */ | ||
1282 | |||
1283 | static t_class *binop3_lo_class; | ||
1284 | |||
1285 | static void *binop3_lo_new(t_floatarg f) | ||
1286 | { | ||
1287 | return (binop3_new(binop3_lo_class, f)); | ||
1288 | } | ||
1289 | |||
1290 | static void binop2_lo_bang(t_binop *x) | ||
1291 | { | ||
1292 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) || (int)(x->x_f2)); | ||
1293 | } | ||
1294 | |||
1295 | static void binop2_lo_float(t_binop *x, t_float f) | ||
1296 | { | ||
1297 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) || (int)(x->x_f2)); | ||
1298 | } | ||
1299 | |||
1300 | /* --------------------------- << ---------------------------- */ | ||
1301 | |||
1302 | static t_class *binop3_ls_class; | ||
1303 | |||
1304 | static void *binop3_ls_new(t_floatarg f) | ||
1305 | { | ||
1306 | return (binop3_new(binop3_ls_class, f)); | ||
1307 | } | ||
1308 | |||
1309 | static void binop2_ls_bang(t_binop *x) | ||
1310 | { | ||
1311 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) << (int)(x->x_f2)); | ||
1312 | } | ||
1313 | |||
1314 | static void binop2_ls_float(t_binop *x, t_float f) | ||
1315 | { | ||
1316 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) << (int)(x->x_f2)); | ||
1317 | } | ||
1318 | |||
1319 | /* --------------------------- >> ---------------------------- */ | ||
1320 | |||
1321 | static t_class *binop3_rs_class; | ||
1322 | |||
1323 | static void *binop3_rs_new(t_floatarg f) | ||
1324 | { | ||
1325 | return (binop3_new(binop3_rs_class, f)); | ||
1326 | } | ||
1327 | |||
1328 | static void binop2_rs_bang(t_binop *x) | ||
1329 | { | ||
1330 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) >> (int)(x->x_f2)); | ||
1331 | } | ||
1332 | |||
1333 | static void binop2_rs_float(t_binop *x, t_float f) | ||
1334 | { | ||
1335 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) >> (int)(x->x_f2)); | ||
1336 | } | ||
1337 | |||
1338 | /* --------------------------- % ---------------------------- */ | ||
1339 | |||
1340 | static t_class *binop3_pc_class; | ||
1341 | |||
1342 | static void *binop3_pc_new(t_floatarg f) | ||
1343 | { | ||
1344 | return (binop3_new(binop3_pc_class, f)); | ||
1345 | } | ||
1346 | |||
1347 | static void binop2_pc_bang(t_binop *x) | ||
1348 | { | ||
1349 | int n2 = x->x_f2; | ||
1350 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1)) % (n2 ? n2 : 1)); | ||
1351 | } | ||
1352 | |||
1353 | static void binop2_pc_float(t_binop *x, t_float f) | ||
1354 | { | ||
1355 | int n2 = x->x_f2; | ||
1356 | outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f)) % (n2 ? n2 : 1)); | ||
1357 | } | ||
1358 | |||
1359 | /* --------------------------- mod ---------------------------- */ | ||
1360 | |||
1361 | static t_class *binop3_mod_class; | ||
1362 | |||
1363 | static void *binop3_mod_new(t_floatarg f) | ||
1364 | { | ||
1365 | return (binop3_new(binop3_mod_class, f)); | ||
1366 | } | ||
1367 | |||
1368 | static void binop3_mod_bang(t_binop *x) | ||
1369 | { | ||
1370 | int n2 = x->x_f2, result; | ||
1371 | if (n2 < 0) n2 = -n2; | ||
1372 | else if (!n2) n2 = 1; | ||
1373 | result = ((int)(x->x_f1)) % n2; | ||
1374 | if (result < 0) result += n2; | ||
1375 | outlet_float(x->x_obj.ob_outlet, (t_float)result); | ||
1376 | } | ||
1377 | |||
1378 | static void binop3_mod_float(t_binop *x, t_float f) | ||
1379 | { | ||
1380 | x->x_f1 = f; | ||
1381 | binop3_mod_bang(x); | ||
1382 | } | ||
1383 | |||
1384 | /* --------------------------- div ---------------------------- */ | ||
1385 | |||
1386 | static t_class *binop3_div_class; | ||
1387 | |||
1388 | static void *binop3_div_new(t_floatarg f) | ||
1389 | { | ||
1390 | return (binop3_new(binop3_div_class, f)); | ||
1391 | } | ||
1392 | |||
1393 | static void binop3_div_bang(t_binop *x) | ||
1394 | { | ||
1395 | int n1 = x->x_f1, n2 = x->x_f2, result; | ||
1396 | if (n2 < 0) n2 = -n2; | ||
1397 | else if (!n2) n2 = 1; | ||
1398 | if (n1 < 0) n1 -= (n2-1); | ||
1399 | result = n1 / n2; | ||
1400 | outlet_float(x->x_obj.ob_outlet, (t_float)result); | ||
1401 | } | ||
1402 | |||
1403 | static void binop3_div_float(t_binop *x, t_float f) | ||
1404 | { | ||
1405 | x->x_f1 = f; | ||
1406 | binop3_div_bang(x); | ||
1407 | } | ||
1408 | |||
1409 | /* -------------------- mathematical functions ------------------ */ | ||
1410 | |||
1411 | static t_class *sin_class; /* ----------- sin --------------- */ | ||
1412 | |||
1413 | static void *sin_new(void) | ||
1414 | { | ||
1415 | t_object *x = (t_object *)pd_new(sin_class); | ||
1416 | outlet_new(x, &s_float); | ||
1417 | return (x); | ||
1418 | } | ||
1419 | |||
1420 | static void sin_float(t_object *x, t_float f) | ||
1421 | { | ||
1422 | outlet_float(x->ob_outlet, sinf(f)); | ||
1423 | } | ||
1424 | |||
1425 | static t_class *cos_class; /* ----------- cos --------------- */ | ||
1426 | |||
1427 | static void *cos_new(void) | ||
1428 | { | ||
1429 | t_object *x = (t_object *)pd_new(cos_class); | ||
1430 | outlet_new(x, &s_float); | ||
1431 | return (x); | ||
1432 | } | ||
1433 | |||
1434 | static void cos_float(t_object *x, t_float f) | ||
1435 | { | ||
1436 | outlet_float(x->ob_outlet, cosf(f)); | ||
1437 | } | ||
1438 | |||
1439 | static t_class *tan_class; /* ----------- tan --------------- */ | ||
1440 | |||
1441 | static void *tan_new(void) | ||
1442 | { | ||
1443 | t_object *x = (t_object *)pd_new(tan_class); | ||
1444 | outlet_new(x, &s_float); | ||
1445 | return (x); | ||
1446 | } | ||
1447 | |||
1448 | static void tan_float(t_object *x, t_float f) | ||
1449 | { | ||
1450 | float c = cosf(f); | ||
1451 | float t = (c == 0 ? 0 : sinf(f)/c); | ||
1452 | outlet_float(x->ob_outlet, t); | ||
1453 | } | ||
1454 | |||
1455 | static t_class *atan_class; /* ----------- atan --------------- */ | ||
1456 | |||
1457 | static void *atan_new(void) | ||
1458 | { | ||
1459 | t_object *x = (t_object *)pd_new(atan_class); | ||
1460 | outlet_new(x, &s_float); | ||
1461 | return (x); | ||
1462 | } | ||
1463 | |||
1464 | static void atan_float(t_object *x, t_float f) | ||
1465 | { | ||
1466 | outlet_float(x->ob_outlet, atanf(f)); | ||
1467 | } | ||
1468 | |||
1469 | static t_class *atan2_class; /* ----------- atan2 --------------- */ | ||
1470 | |||
1471 | typedef struct _atan2 | ||
1472 | { | ||
1473 | t_object x_ob; | ||
1474 | float x_y; | ||
1475 | } t_atan2; | ||
1476 | |||
1477 | static void *atan2_new(void) | ||
1478 | { | ||
1479 | t_atan2 *x = (t_atan2 *)pd_new(atan2_class); | ||
1480 | floatinlet_new(&x->x_ob, &x->x_y); | ||
1481 | outlet_new(&x->x_ob, &s_float); | ||
1482 | return (x); | ||
1483 | } | ||
1484 | |||
1485 | static void atan2_float(t_atan2 *x, t_float f) | ||
1486 | { | ||
1487 | float r = (f == 0 && x->x_y == 0 ? 0 : atan2f(x->x_y, f)); | ||
1488 | outlet_float(x->x_ob.ob_outlet, r); | ||
1489 | } | ||
1490 | |||
1491 | static t_class *sqrt_class; /* ----------- sqrt --------------- */ | ||
1492 | |||
1493 | static void *sqrt_new(void) | ||
1494 | { | ||
1495 | t_object *x = (t_object *)pd_new(sqrt_class); | ||
1496 | outlet_new(x, &s_float); | ||
1497 | return (x); | ||
1498 | } | ||
1499 | |||
1500 | static void sqrt_float(t_object *x, t_float f) | ||
1501 | { | ||
1502 | float r = (f > 0 ? sqrtf(f) : 0); | ||
1503 | outlet_float(x->ob_outlet, r); | ||
1504 | } | ||
1505 | |||
1506 | static t_class *log_class; /* ----------- log --------------- */ | ||
1507 | |||
1508 | static void *log_new(void) | ||
1509 | { | ||
1510 | t_object *x = (t_object *)pd_new(log_class); | ||
1511 | outlet_new(x, &s_float); | ||
1512 | return (x); | ||
1513 | } | ||
1514 | |||
1515 | static void log_float(t_object *x, t_float f) | ||
1516 | { | ||
1517 | float r = (f > 0 ? logf(f) : -1000); | ||
1518 | outlet_float(x->ob_outlet, r); | ||
1519 | } | ||
1520 | |||
1521 | |||
1522 | static t_class *exp_class; /* ----------- exp --------------- */ | ||
1523 | |||
1524 | static void *exp_new(void) | ||
1525 | { | ||
1526 | t_object *x = (t_object *)pd_new(exp_class); | ||
1527 | outlet_new(x, &s_float); | ||
1528 | return (x); | ||
1529 | } | ||
1530 | |||
1531 | #define MAXLOG 87.3365 | ||
1532 | static void exp_float(t_object *x, t_float f) | ||
1533 | { | ||
1534 | float g; | ||
1535 | #ifdef MSW | ||
1536 | char buf[10]; | ||
1537 | #endif | ||
1538 | if (f > MAXLOG) f = MAXLOG; | ||
1539 | g = expf(f); | ||
1540 | outlet_float(x->ob_outlet, g); | ||
1541 | } | ||
1542 | |||
1543 | static t_class *abs_class; /* ----------- abs --------------- */ | ||
1544 | |||
1545 | static void *abs_new(void) | ||
1546 | { | ||
1547 | t_object *x = (t_object *)pd_new(abs_class); | ||
1548 | outlet_new(x, &s_float); | ||
1549 | return (x); | ||
1550 | } | ||
1551 | |||
1552 | static void abs_float(t_object *x, t_float f) | ||
1553 | { | ||
1554 | outlet_float(x->ob_outlet, fabsf(f)); | ||
1555 | } | ||
1556 | |||
1557 | /* ------------------------ misc ------------------------ */ | ||
1558 | |||
1559 | static t_class *clip_class; | ||
1560 | |||
1561 | typedef struct _clip | ||
1562 | { | ||
1563 | t_object x_ob; | ||
1564 | float x_f1; | ||
1565 | float x_f2; | ||
1566 | } t_clip; | ||
1567 | |||
1568 | static void *clip_new(t_floatarg f1, t_floatarg f2) | ||
1569 | { | ||
1570 | t_clip *x = (t_clip *)pd_new(clip_class); | ||
1571 | floatinlet_new(&x->x_ob, &x->x_f1); | ||
1572 | floatinlet_new(&x->x_ob, &x->x_f2); | ||
1573 | outlet_new(&x->x_ob, &s_float); | ||
1574 | x->x_f1 = f1; | ||
1575 | x->x_f2 = f2; | ||
1576 | return (x); | ||
1577 | } | ||
1578 | |||
1579 | static void clip_float(t_clip *x, t_float f) | ||
1580 | { | ||
1581 | outlet_float(x->x_ob.ob_outlet, (f < x->x_f1 ? x->x_f1 : ( | ||
1582 | f > x->x_f2 ? x->x_f2 : f))); | ||
1583 | } | ||
1584 | |||
1585 | static void clip_setup(void) | ||
1586 | { | ||
1587 | clip_class = class_new(gensym("clip"), (t_newmethod)clip_new, 0, | ||
1588 | sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0); | ||
1589 | class_addfloat(clip_class, clip_float); | ||
1590 | } | ||
1591 | |||
1592 | void x_arithmetic_setup(void) | ||
1593 | { | ||
1594 | t_symbol *binop1_sym = gensym("operators"); | ||
1595 | t_symbol *binop23_sym = gensym("otherbinops"); | ||
1596 | t_symbol *math_sym = gensym("math"); | ||
1597 | |||
1598 | binop1_plus_class = class_new(gensym("+"), (t_newmethod)binop1_plus_new, 0, | ||
1599 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1600 | class_addbang(binop1_plus_class, binop1_plus_bang); | ||
1601 | class_addfloat(binop1_plus_class, (t_method)binop1_plus_float); | ||
1602 | class_sethelpsymbol(binop1_plus_class, binop1_sym); | ||
1603 | |||
1604 | binop1_minus_class = class_new(gensym("-"), | ||
1605 | (t_newmethod)binop1_minus_new, 0, | ||
1606 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1607 | class_addbang(binop1_minus_class, binop1_minus_bang); | ||
1608 | class_addfloat(binop1_minus_class, (t_method)binop1_minus_float); | ||
1609 | class_sethelpsymbol(binop1_minus_class, binop1_sym); | ||
1610 | |||
1611 | binop1_times_class = class_new(gensym("*"), | ||
1612 | (t_newmethod)binop1_times_new, 0, | ||
1613 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1614 | class_addbang(binop1_times_class, binop1_times_bang); | ||
1615 | class_addfloat(binop1_times_class, (t_method)binop1_times_float); | ||
1616 | class_sethelpsymbol(binop1_times_class, binop1_sym); | ||
1617 | |||
1618 | binop1_div_class = class_new(gensym("/"), | ||
1619 | (t_newmethod)binop1_div_new, 0, | ||
1620 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1621 | class_addbang(binop1_div_class, binop1_div_bang); | ||
1622 | class_addfloat(binop1_div_class, (t_method)binop1_div_float); | ||
1623 | class_sethelpsymbol(binop1_div_class, binop1_sym); | ||
1624 | |||
1625 | binop1_pow_class = class_new(gensym("pow"), | ||
1626 | (t_newmethod)binop1_pow_new, 0, | ||
1627 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1628 | class_addbang(binop1_pow_class, binop1_pow_bang); | ||
1629 | class_addfloat(binop1_pow_class, (t_method)binop1_pow_float); | ||
1630 | class_sethelpsymbol(binop1_pow_class, binop1_sym); | ||
1631 | |||
1632 | binop1_max_class = class_new(gensym("max"), | ||
1633 | (t_newmethod)binop1_max_new, 0, | ||
1634 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1635 | class_addbang(binop1_max_class, binop1_max_bang); | ||
1636 | class_addfloat(binop1_max_class, (t_method)binop1_max_float); | ||
1637 | class_sethelpsymbol(binop1_max_class, binop1_sym); | ||
1638 | |||
1639 | binop1_min_class = class_new(gensym("min"), | ||
1640 | (t_newmethod)binop1_min_new, 0, | ||
1641 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1642 | class_addbang(binop1_min_class, binop1_min_bang); | ||
1643 | class_addfloat(binop1_min_class, (t_method)binop1_min_float); | ||
1644 | class_sethelpsymbol(binop1_min_class, binop1_sym); | ||
1645 | |||
1646 | /* ------------------ binop2 ----------------------- */ | ||
1647 | |||
1648 | binop2_ee_class = class_new(gensym("=="), (t_newmethod)binop2_ee_new, 0, | ||
1649 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1650 | class_addbang(binop2_ee_class, binop2_ee_bang); | ||
1651 | class_addfloat(binop2_ee_class, (t_method)binop2_ee_float); | ||
1652 | class_sethelpsymbol(binop2_ee_class, binop23_sym); | ||
1653 | |||
1654 | binop2_ne_class = class_new(gensym("!="), (t_newmethod)binop2_ne_new, 0, | ||
1655 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1656 | class_addbang(binop2_ne_class, binop2_ne_bang); | ||
1657 | class_addfloat(binop2_ne_class, (t_method)binop2_ne_float); | ||
1658 | class_sethelpsymbol(binop2_ne_class, binop23_sym); | ||
1659 | |||
1660 | binop2_gt_class = class_new(gensym(">"), (t_newmethod)binop2_gt_new, 0, | ||
1661 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1662 | class_addbang(binop2_gt_class, binop2_gt_bang); | ||
1663 | class_addfloat(binop2_gt_class, (t_method)binop2_gt_float); | ||
1664 | class_sethelpsymbol(binop2_gt_class, binop23_sym); | ||
1665 | |||
1666 | binop2_lt_class = class_new(gensym("<"), (t_newmethod)binop2_lt_new, 0, | ||
1667 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1668 | class_addbang(binop2_lt_class, binop2_lt_bang); | ||
1669 | class_addfloat(binop2_lt_class, (t_method)binop2_lt_float); | ||
1670 | class_sethelpsymbol(binop2_lt_class, binop23_sym); | ||
1671 | |||
1672 | binop2_ge_class = class_new(gensym(">="), (t_newmethod)binop2_ge_new, 0, | ||
1673 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1674 | class_addbang(binop2_ge_class, binop2_ge_bang); | ||
1675 | class_addfloat(binop2_ge_class, (t_method)binop2_ge_float); | ||
1676 | class_sethelpsymbol(binop2_ge_class, binop23_sym); | ||
1677 | |||
1678 | binop2_le_class = class_new(gensym("<="), (t_newmethod)binop2_le_new, 0, | ||
1679 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1680 | class_addbang(binop2_le_class, binop2_le_bang); | ||
1681 | class_addfloat(binop2_le_class, (t_method)binop2_le_float); | ||
1682 | class_sethelpsymbol(binop2_le_class, binop23_sym); | ||
1683 | |||
1684 | /* ------------------ binop3 ----------------------- */ | ||
1685 | |||
1686 | binop3_ba_class = class_new(gensym("&"), (t_newmethod)binop3_ba_new, 0, | ||
1687 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1688 | class_addbang(binop3_ba_class, binop2_ba_bang); | ||
1689 | class_addfloat(binop3_ba_class, (t_method)binop2_ba_float); | ||
1690 | class_sethelpsymbol(binop3_ba_class, binop23_sym); | ||
1691 | |||
1692 | binop3_la_class = class_new(gensym("&&"), (t_newmethod)binop3_la_new, 0, | ||
1693 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1694 | class_addbang(binop3_la_class, binop2_la_bang); | ||
1695 | class_addfloat(binop3_la_class, (t_method)binop2_la_float); | ||
1696 | class_sethelpsymbol(binop3_la_class, binop23_sym); | ||
1697 | |||
1698 | binop3_bo_class = class_new(gensym("|"), (t_newmethod)binop3_bo_new, 0, | ||
1699 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1700 | class_addbang(binop3_bo_class, binop2_bo_bang); | ||
1701 | class_addfloat(binop3_bo_class, (t_method)binop2_bo_float); | ||
1702 | class_sethelpsymbol(binop3_bo_class, binop23_sym); | ||
1703 | |||
1704 | binop3_lo_class = class_new(gensym("||"), (t_newmethod)binop3_lo_new, 0, | ||
1705 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1706 | class_addbang(binop3_lo_class, binop2_lo_bang); | ||
1707 | class_addfloat(binop3_lo_class, (t_method)binop2_lo_float); | ||
1708 | class_sethelpsymbol(binop3_lo_class, binop23_sym); | ||
1709 | |||
1710 | binop3_ls_class = class_new(gensym("<<"), (t_newmethod)binop3_ls_new, 0, | ||
1711 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1712 | class_addbang(binop3_ls_class, binop2_ls_bang); | ||
1713 | class_addfloat(binop3_ls_class, (t_method)binop2_ls_float); | ||
1714 | class_sethelpsymbol(binop3_ls_class, binop23_sym); | ||
1715 | |||
1716 | binop3_rs_class = class_new(gensym(">>"), (t_newmethod)binop3_rs_new, 0, | ||
1717 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1718 | class_addbang(binop3_rs_class, binop2_rs_bang); | ||
1719 | class_addfloat(binop3_rs_class, (t_method)binop2_rs_float); | ||
1720 | class_sethelpsymbol(binop3_rs_class, binop23_sym); | ||
1721 | |||
1722 | binop3_pc_class = class_new(gensym("%"), (t_newmethod)binop3_pc_new, 0, | ||
1723 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1724 | class_addbang(binop3_pc_class, binop2_pc_bang); | ||
1725 | class_addfloat(binop3_pc_class, (t_method)binop2_pc_float); | ||
1726 | class_sethelpsymbol(binop3_pc_class, binop23_sym); | ||
1727 | |||
1728 | binop3_mod_class = class_new(gensym("mod"), (t_newmethod)binop3_mod_new, 0, | ||
1729 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1730 | class_addbang(binop3_mod_class, binop3_mod_bang); | ||
1731 | class_addfloat(binop3_mod_class, (t_method)binop3_mod_float); | ||
1732 | class_sethelpsymbol(binop3_mod_class, binop23_sym); | ||
1733 | |||
1734 | binop3_div_class = class_new(gensym("div"), (t_newmethod)binop3_div_new, 0, | ||
1735 | sizeof(t_binop), 0, A_DEFFLOAT, 0); | ||
1736 | class_addbang(binop3_div_class, binop3_div_bang); | ||
1737 | class_addfloat(binop3_div_class, (t_method)binop3_div_float); | ||
1738 | class_sethelpsymbol(binop3_div_class, binop23_sym); | ||
1739 | |||
1740 | /* ------------------- math functions --------------- */ | ||
1741 | |||
1742 | sin_class = class_new(gensym("sin"), sin_new, 0, | ||
1743 | sizeof(t_object), 0, 0); | ||
1744 | class_addfloat(sin_class, (t_method)sin_float); | ||
1745 | class_sethelpsymbol(sin_class, math_sym); | ||
1746 | |||
1747 | cos_class = class_new(gensym("cos"), cos_new, 0, | ||
1748 | sizeof(t_object), 0, 0); | ||
1749 | class_addfloat(cos_class, (t_method)cos_float); | ||
1750 | class_sethelpsymbol(cos_class, math_sym); | ||
1751 | |||
1752 | tan_class = class_new(gensym("tan"), tan_new, 0, | ||
1753 | sizeof(t_object), 0, 0); | ||
1754 | class_addfloat(tan_class, (t_method)tan_float); | ||
1755 | class_sethelpsymbol(tan_class, math_sym); | ||
1756 | |||
1757 | atan_class = class_new(gensym("atan"), atan_new, 0, | ||
1758 | sizeof(t_object), 0, 0); | ||
1759 | class_addfloat(atan_class, (t_method)atan_float); | ||
1760 | class_sethelpsymbol(atan_class, math_sym); | ||
1761 | |||
1762 | atan2_class = class_new(gensym("atan2"), atan2_new, 0, | ||
1763 | sizeof(t_atan2), 0, 0); | ||
1764 | class_addfloat(atan2_class, (t_method)atan2_float); | ||
1765 | class_sethelpsymbol(atan2_class, math_sym); | ||
1766 | |||
1767 | sqrt_class = class_new(gensym("sqrt"), sqrt_new, 0, | ||
1768 | sizeof(t_object), 0, 0); | ||
1769 | class_addfloat(sqrt_class, (t_method)sqrt_float); | ||
1770 | class_sethelpsymbol(sqrt_class, math_sym); | ||
1771 | |||
1772 | log_class = class_new(gensym("log"), log_new, 0, | ||
1773 | sizeof(t_object), 0, 0); | ||
1774 | class_addfloat(log_class, (t_method)log_float); | ||
1775 | class_sethelpsymbol(log_class, math_sym); | ||
1776 | |||
1777 | exp_class = class_new(gensym("exp"), exp_new, 0, | ||
1778 | sizeof(t_object), 0, 0); | ||
1779 | class_addfloat(exp_class, (t_method)exp_float); | ||
1780 | class_sethelpsymbol(exp_class, math_sym); | ||
1781 | |||
1782 | abs_class = class_new(gensym("abs"), abs_new, 0, | ||
1783 | sizeof(t_object), 0, 0); | ||
1784 | class_addfloat(abs_class, (t_method)abs_float); | ||
1785 | class_sethelpsymbol(abs_class, math_sym); | ||
1786 | |||
1787 | /* ------------------------ misc ------------------------ */ | ||
1788 | |||
1789 | clip_setup(); | ||
1790 | } | ||
1791 | |||
1792 | |||