int f_shiftl(int argc, const int *argt, void **args) { CELL *res = args[0]; CELL *arg1 = args[1]; CELL *arg2 = args[2]; int i; if (argc < 2) return E_ARG_LO; if (argc > 2) return E_ARG_HI; if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE) return E_ARG_TYPE; if (argt[0] != CELL_TYPE) return E_RES_TYPE; for (i = 0; i < columns; i++) { if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i])) SET_NULL_C(&res[i]); else res[i] = arg1[i] << arg2[i]; } return 0; }
int f_or2(int argc, const int *argt, void **args) { CELL *res = args[0]; int i, j; if (argc < 1) return E_ARG_LO; if (argt[0] != CELL_TYPE) return E_RES_TYPE; for (i = 1; i <= argc; i++) if (argt[i] != argt[0]) return E_ARG_TYPE; for (i = 0; i < columns; i++) { res[i] = 0; for (j = 1; j <= argc; j++) { CELL *arg = args[j]; if (!IS_NULL_C(&arg[i]) && arg[i]) { res[i] = 1; break; } if (IS_NULL_C(&arg[i])) SET_NULL_C(&res[i]); } } return 0; }
int f_eq(int argc, const int *argt, void **args) { CELL *res = args[0]; int i; if (argc < 2) return E_ARG_LO; if (argc > 2) return E_ARG_HI; switch (argt[1]) { case CELL_TYPE: { CELL *arg1 = args[1]; CELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i])) SET_NULL_C(&res[i]); else res[i] = arg1[i] == arg2[i]; } return 0; } case FCELL_TYPE: { FCELL *arg1 = args[1]; FCELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i])) SET_NULL_C(&res[i]); else res[i] = arg1[i] == arg2[i]; } return 0; } case DCELL_TYPE: { DCELL *arg1 = args[1]; DCELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i])) SET_NULL_C(&res[i]); else res[i] = arg1[i] == arg2[i]; } return 0; } default: return E_INV_TYPE; } }
int f_bitor(int argc, const int *argt, void **args) { CELL *res = args[0]; CELL **argz = (CELL **) args; int i, j; if (argc < 1) return E_ARG_LO; if (argt[0] != CELL_TYPE) return E_RES_TYPE; for (i = 1; i <= argc; i++) if (argt[i] != CELL_TYPE) return E_ARG_TYPE; for (i = 0; i < columns; i++) { res[i] = 0; for (j = 1; j <= argc; j++) { if (IS_NULL_C(&argz[j][i])) { SET_NULL_C(&res[i]); break; } res[i] |= argz[j][i]; } } return 0; }
int f_double(int argc, const int *argt, void **args) { DCELL *res = args[0]; int i; if (argc < 1) return E_ARG_LO; if (argc > 1) return E_ARG_HI; if (argt[0] != DCELL_TYPE) return E_RES_TYPE; switch (argt[1]) { case CELL_TYPE: { CELL *arg1 = args[1]; for (i = 0; i < columns; i++) if (IS_NULL_C(&arg1[i])) SET_NULL_D(&res[i]); else res[i] = (DCELL) arg1[i]; return 0; } case FCELL_TYPE: { FCELL *arg1 = args[1]; for (i = 0; i < columns; i++) if (IS_NULL_F(&arg1[i])) SET_NULL_D(&res[i]); else res[i] = (DCELL) arg1[i]; return 0; } case DCELL_TYPE: { DCELL *arg1 = args[1]; for (i = 0; i < columns; i++) if (IS_NULL_D(&arg1[i])) SET_NULL_D(&res[i]); else res[i] = (DCELL) arg1[i]; return 0; } default: return E_INV_TYPE; } }
int f_isnull(int argc, const int *argt, void **args) { int *res = args[0]; int i; if (argc < 1) return E_ARG_LO; if (argc > 1) return E_ARG_HI; if (argt[0] != CELL_TYPE) return E_RES_TYPE; switch (argt[1]) { case CELL_TYPE: { CELL *arg1 = args[1]; for (i = 0; i < columns; i++) res[i] = IS_NULL_C(&arg1[i]) ? 1 : 0; return 0; } case FCELL_TYPE: { FCELL *arg1 = args[1]; for (i = 0; i < columns; i++) res[i] = IS_NULL_F(&arg1[i]) ? 1 : 0; return 0; } case DCELL_TYPE: { DCELL *arg1 = args[1]; for (i = 0; i < columns; i++) res[i] = IS_NULL_D(&arg1[i]) ? 1 : 0; return 0; } default: return E_INV_TYPE; } }
int f_max(int argc, const int *argt, void **args) { int i, j; if (argc < 1) return E_ARG_LO; for (i = 1; i <= argc; i++) if (argt[i] != argt[0]) return E_ARG_TYPE; switch (argt[0]) { case CELL_TYPE: { CELL *res = args[0]; CELL **argz = (CELL **) args; for (i = 0; i < columns; i++) { int nul = 0; CELL max; for (j = 1; j <= argc; j++) if (IS_NULL_C(&argz[j][i])) nul = 1; else if (j == 1) max = argz[j][i]; else if (max < argz[j][i]) max = argz[j][i]; if (nul) SET_NULL_C(&res[i]); else res[i] = max; } return 0; } case FCELL_TYPE: { FCELL *res = args[0]; FCELL **argz = (FCELL **) args; for (i = 0; i < columns; i++) { int nul = 0; FCELL max; for (j = 1; j <= argc; j++) if (IS_NULL_F(&argz[j][i])) nul = 1; else if (j == 1) max = argz[j][i]; else if (max < argz[j][i]) max = argz[j][i]; if (nul) SET_NULL_F(&res[i]); else res[i] = max; } return 0; } case DCELL_TYPE: { DCELL *res = args[0]; DCELL **argz = (DCELL **) args; for (i = 0; i < columns; i++) { int nul = 0; DCELL max; for (j = 1; j <= argc; j++) if (IS_NULL_D(&argz[j][i])) nul = 1; else if (j == 1) max = argz[j][i]; else if (max < argz[j][i]) max = argz[j][i]; if (nul) SET_NULL_D(&res[i]); else res[i] = max; } return 0; } default: return E_INV_TYPE; } }
int f_mul(int argc, const int *argt, void **args) { int i, j; if (argc < 1) return E_ARG_LO; for (i = 1; i <= argc; i++) if (argt[i] != argt[0]) return E_ARG_TYPE; switch (argt[0]) { case CELL_TYPE: { CELL *res = args[0]; CELL **argz = (CELL **) args; for (i = 0; i < columns; i++) { res[i] = 1; for (j = 1; j <= argc; j++) { if (IS_NULL_C(&argz[j][i])) { SET_NULL_C(&res[i]); break; } res[i] *= argz[j][i]; } } return 0; } case FCELL_TYPE: { FCELL *res = args[0]; FCELL **argz = (FCELL **) args; for (i = 0; i < columns; i++) { res[i] = 1; for (j = 1; j <= argc; j++) { if (IS_NULL_F(&argz[j][i])) { SET_NULL_F(&res[i]); break; } res[i] *= argz[j][i]; } } return 0; } case DCELL_TYPE: { DCELL *res = args[0]; DCELL **argz = (DCELL **) args; for (i = 0; i < columns; i++) { res[i] = 1; for (j = 1; j <= argc; j++) { if (IS_NULL_D(&argz[j][i])) { SET_NULL_D(&res[i]); break; } res[i] *= argz[j][i]; } } return 0; } default: return E_INV_TYPE; } }
int f_mode(int argc, const int *argt, void **args) { static double *value; static int value_size; int size = argc * sizeof(double); int i, j; if (argc < 1) return E_ARG_LO; for (i = 1; i <= argc; i++) if (argt[i] != argt[0]) return E_ARG_TYPE; if (size > value_size) { value_size = size; value = G_realloc(value, value_size); } switch (argt[argc]) { case CELL_TYPE: { CELL *res = args[0]; CELL **argv = (CELL **) & args[1]; for (i = 0; i < columns; i++) { int nv = 0; for (j = 0; j < argc && !nv; j++) { if (IS_NULL_C(&argv[j][i])) nv = 1; else value[j] = (double)argv[j][i]; } if (nv) SET_NULL_C(&res[i]); else res[i] = (CELL) mode(value, argc); } return 0; } case FCELL_TYPE: { FCELL *res = args[0]; FCELL **argv = (FCELL **) & args[1]; for (i = 0; i < columns; i++) { int nv = 0; for (j = 0; j < argc && !nv; j++) { if (IS_NULL_F(&argv[j][i])) nv = 1; else value[j] = (double)argv[j][i]; } if (nv) SET_NULL_F(&res[i]); else res[i] = (FCELL) mode(value, argc); } return 0; } case DCELL_TYPE: { DCELL *res = args[0]; DCELL **argv = (DCELL **) & args[1]; for (i = 0; i < columns; i++) { int nv = 0; for (j = 0; j < argc && !nv; j++) { if (IS_NULL_D(&argv[j][i])) nv = 1; else value[j] = (double)argv[j][i]; } if (nv) SET_NULL_D(&res[i]); else res[i] = (DCELL) mode(value, argc); } return 0; } default: return E_INV_TYPE; } }
int f_div(int argc, const int *argt, void **args) { int i; if (argc < 2) return E_ARG_LO; if (argc > 2) return E_ARG_HI; if (argt[1] != argt[0] || argt[2] != argt[0]) return E_ARG_TYPE; switch (argt[0]) { case CELL_TYPE: { CELL *res = args[0]; CELL *arg1 = args[1]; CELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) || arg2[i] == 0) SET_NULL_C(&res[i]); else res[i] = arg1[i] / arg2[i]; } return 0; } case FCELL_TYPE: { FCELL *res = args[0]; FCELL *arg1 = args[1]; FCELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]) || arg2[i] == 0.0f) SET_NULL_F(&res[i]); else { floating_point_exception = 0; res[i] = arg1[i] / arg2[i]; if (floating_point_exception) SET_NULL_F(&res[i]); } } return 0; } case DCELL_TYPE: { DCELL *res = args[0]; DCELL *arg1 = args[1]; DCELL *arg2 = args[2]; for (i = 0; i < columns; i++) { if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]) || arg2[i] == 0.0) SET_NULL_D(&res[i]); else { floating_point_exception = 0; res[i] = arg1[i] / arg2[i]; if (floating_point_exception) SET_NULL_D(&res[i]); } } return 0; } default: return E_INV_TYPE; } }