t_real qtrn_get_norm(const t_qtrn *const q) { if (q->type == CARTHESIAN) return (XP(q) * XP(q) + YP(q) * YP(q) + ZP(q) * ZP(q) + WP(q) * WP(q)); else if (q->type == CYLINDRICAL) return (ZP(q) * ZP(q) + QRP(q) * QRP(q)); else return (QRHOP(q)); }
/* {{{ php_foreach_cat */ static int php_foreach_cat (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata) { int err; err = ypprot_err (instatus); if (!err) { if (inkeylen) { char *key = emalloc(inkeylen+1); strlcpy(key, inkey, inkeylen+1); add_assoc_stringl_ex((zval *) indata, key, inkeylen+1, inval, invallen, 1); efree(key); } return 0; } if (err != YPERR_NOMORE) { TSRMLS_FETCH(); YP(error) = err; php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (err)); } return 0; }
t_qtrn qtrn_external_prod(const t_qtrn *const a, const t_real s) { t_qtrn ans; ans.type = a->type; if (a->type == CARTHESIAN) { X(ans) = XP(a) * s; Y(ans) = YP(a) * s; Z(ans) = ZP(a) * s; W(ans) = WP(a) * s; } else if (a->type == CYLINDRICAL) { QR(ans) = QRP(a) * s; QTHETA(ans) = QTHETAP(a); Z(ans) = ZP(a) * s; W(ans) = WP(a) * s; } else { QRHO(ans) = QRHOP(a) * s; QTHETA(ans) = QTHETAP(a); QPHI(ans) = QPHIP(a); W(ans) = WP(a) * s; } return (ans); }
void polar2carth(t_cmplx *v) { const t_real m = MODP(v); const t_real a = ARGP(v); XP(v) = m * cos(a); YP(v) = m * sin(a); v->type = CARTHESIAN; }
void carth2polar(t_cmplx *v) { const t_real x = XP(v); const t_real y = YP(v); MODP(v) = sqrt(x * x + y * y); ARGP(v) = atan2(y, x); v->type = POLAR; }
void spher2carth(t_vec3t *v) { const t_real r = RHOP(v); const t_real t = THETAP(v); const t_real p = PHIP(v); XP(v) = r * sin(p) * cos(t); YP(v) = r * sin(p) * sin(t); ZP(v) = r * cos(p); v->type = CARTHESIAN; }
void carth2spher(t_vec3t *v) { const t_real x = XP(v); const t_real y = YP(v); const t_real z = ZP(v); RHOP(v) = sqrt(x * x + y * y + z * z); THETAP(v) = atan2(y, x); PHIP(v) = acos(z / RHOP(v)); v->type = SPHERICAL; }
t_qtrn qtrn_get_conj(const t_qtrn *const q) { if (q->type == CARTHESIAN) return (NEW_QTRN(-XP(q), -YP(q), -ZP(q), WP(q))); else if (q->type == CYLINDRICAL) return ((t_qtrn){CYLINDRICAL, {{ QRP(q), QTHETAP(q) + M_PI, -ZP(q), WP(q)}}}); else return ((t_qtrn){SPHERICAL, {{ QRHOP(q), QTHETAP(q) + M_PI, QPHIP(q) + M_PI, WP(q)}}}); }
void qtrn_conj(t_qtrn *const q) { if (q->type == CARTHESIAN) { XP(q) *= -1; YP(q) *= -1; ZP(q) *= -1; } else if (q->type == CYLINDRICAL) { QTHETAP(q) += M_PI; ZP(q) *= -1; } else { QTHETAP(q) += M_PI; QPHIP(q) += M_PI; } }
void qtrn_external_mult(t_qtrn *const a, const t_real s) { if (a->type == CARTHESIAN) { XP(a) *= s; YP(a) *= s; ZP(a) *= s; WP(a) *= s; } else if (a->type == CYLINDRICAL) { QRP(a) *= s; ZP(a) *= s; WP(a) *= s; } else { QRHOP(a) *= s; WP(a) *= s; } }