/* * call-seq: * OCI8::Math.log(numeric) -> oranumber * OCI8::Math.log(numeric, base_num) -> oranumber * * Returns the natural logarithm of <i>numeric</i> for one argument. * Returns the base <i>base_num</i> logarithm of <i>numeric</i> for two arguments. */ static VALUE omath_log(int argc, VALUE *argv, VALUE obj) { OCIError *errhp = oci8_errhp; VALUE num, base; OCINumber n; OCINumber b; OCINumber r; sword sign; rb_scan_args(argc, argv, "11", &num, &base); set_oci_number_from_num(&n, num, 1, errhp); oci_lc(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log"); if (NIL_P(base)) { oci_lc(OCINumberLn(errhp, &n, &r)); } else { set_oci_number_from_num(&b, base, 1, errhp); oci_lc(OCINumberSign(errhp, &b, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for the base of log"); oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign)); if (sign == 0) rb_raise(rb_eRangeError, "base 1 for log"); oci_lc(OCINumberLog(errhp, &b, &n, &r)); } return oci8_make_ocinumber(&r, errhp); }
/* * call-seq: * OCI8::Math.atan2(y, x) -> oranumber * * Computes the arc tangent given <i>y</i> and <i>x</i>. Returns * -PI..PI. */ static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate) { OCIError *errhp = oci8_errhp; OCINumber nY; OCINumber nX; OCINumber rv; boolean is_zero; sword sign; set_oci_number_from_num(&nX, Xcoordinate, 1, errhp); set_oci_number_from_num(&nY, Ycoordinate, 1, errhp); /* check zero */ chkerr(OCINumberIsZero(errhp, &nX, &is_zero)); if (is_zero) { chkerr(OCINumberSign(errhp, &nY, &sign)); switch (sign) { case 0: return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */ case 1: return oci8_make_ocinumber(&const_PI2, errhp); /* atan2(positive, 0) => PI/2 */ case -1: return oci8_make_ocinumber(&const_mPI2, errhp); /* atan2(negative, 0) => -PI/2 */ } } /* atan2 */ chkerr(OCINumberArcTan2(errhp, &nY, &nX, &rv)); return oci8_make_ocinumber(&rv, errhp); }
/* * call-seq: * OCI8::Math.log10(numeric) -> oranumber * * Returns the base 10 logarithm of <i>numeric</i>. */ static VALUE omath_log10(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; set_oci_number_from_num(&n, num, 1, errhp); chkerr(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log10"); chkerr(OCINumberLog(errhp, &const_p10, &n, &r)); return oci8_make_ocinumber(&r, errhp); }
/* * call-seq: * OCI8::Math.sqrt(numeric) -> oranumber * * Returns the non-negative square root of <i>numeric</i>. */ static VALUE omath_sqrt(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; set_oci_number_from_num(&n, num, 1, errhp); /* check whether num is negative */ chkerr(OCINumberSign(errhp, &n, &sign)); if (sign < 0) { errno = EDOM; rb_sys_fail("sqrt"); } chkerr(OCINumberSqrt(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); }