Module: OCI8::Math
- Defined in:
- ext/oci8/ocinumber.c,
ext/oci8/ocinumber.c
Overview
The OCI8::Math
module contains module functions for basic trigonometric and transcendental functions. Their accuracy is same with OraNumber.
Constant Summary collapse
- PI =
The ratio of the circumference of a circle to its diameter.
obj_PI
Class Method Summary collapse
-
.acos(x) ⇒ OraNumber
Computes the principal value of the arc cosine of x.
-
.asin(x) ⇒ OraNumber
Computes the principal value of the arc sine of x.
-
.atan(x) ⇒ OraNumber
Computes the principal value of the arc tangent of their argument x.
-
.atan2(y, x) ⇒ OraNumber
Computes the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.
-
.cos(x) ⇒ OraNumber
Computes the cosine of x, measured in radians.
-
.cosh(x) ⇒ OraNumber
Computes the hyperbolic cosine of x.
-
.exp(x) ⇒ OraNumber
Computes the base- e exponential of x.
- .log(*args) ⇒ Object
-
.log10(x) ⇒ OraNumber
Computes the base 10 logarithm of x.
-
.sin(x) ⇒ OraNumber
Computes the sine of x, measured in radians.
-
.sinh(x) ⇒ OraNumber
Computes the hyperbolic sine of x.
-
.sqrt(x) ⇒ OraNumber
Computes the square root of x.
-
.tan(x) ⇒ OraNumber
Computes the tangent of x, measured in radians.
-
.tanh(x) ⇒ OraNumber
Computes the hyperbolic tangent of x.
Class Method Details
.acos(x) ⇒ OraNumber
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'ext/oci8/ocinumber.c', line 488 static VALUE omath_acos(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for acos"); /* check lower bound */ chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for acos"); /* acos */ chkerr(OCINumberArcCos(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); } |
.asin(x) ⇒ OraNumber
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'ext/oci8/ocinumber.c', line 517 static VALUE omath_asin(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; sword sign; set_oci_number_from_num(&n, num, 1, errhp); /* check upper bound */ chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign)); if (sign > 0) rb_raise(rb_eRangeError, "out of range for asin"); /* check lower bound */ chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign)); if (sign < 0) rb_raise(rb_eRangeError, "out of range for asin"); /* asin */ chkerr(OCINumberArcSin(errhp, &n, &r)); return oci8_make_ocinumber(&r, errhp); } |
.atan(x) ⇒ OraNumber
546 547 548 549 550 551 552 553 554 |
# File 'ext/oci8/ocinumber.c', line 546 static VALUE omath_atan(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; chkerr(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } |
.atan2(y, x) ⇒ OraNumber
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'ext/oci8/ocinumber.c', line 397 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); } |
.cos(x) ⇒ OraNumber
434 435 436 437 438 439 440 441 442 |
# File 'ext/oci8/ocinumber.c', line 434 static VALUE omath_cos(VALUE obj, VALUE radian) { OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; chkerr(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } |
.cosh(x) ⇒ OraNumber
564 565 566 567 568 569 570 571 572 |
# File 'ext/oci8/ocinumber.c', line 564 static VALUE omath_cosh(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; chkerr(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } |
.exp(x) ⇒ OraNumber
618 619 620 621 622 623 624 625 626 |
# File 'ext/oci8/ocinumber.c', line 618 static VALUE omath_exp(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; chkerr(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } |
.log(x) ⇒ OraNumber .log(x, y) ⇒ OraNumber
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
# File 'ext/oci8/ocinumber.c', line 644 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); chkerr(OCINumberSign(errhp, &n, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for log"); if (NIL_P(base)) { chkerr(OCINumberLn(errhp, &n, &r)); } else { set_oci_number_from_num(&b, base, 1, errhp); chkerr(OCINumberSign(errhp, &b, &sign)); if (sign <= 0) rb_raise(rb_eRangeError, "nonpositive value for the base of log"); chkerr(OCINumberCmp(errhp, &b, &const_p1, &sign)); if (sign == 0) rb_raise(rb_eRangeError, "base 1 for log"); chkerr(OCINumberLog(errhp, &b, &n, &r)); } return oci8_make_ocinumber(&r, errhp); } |
.log10(x) ⇒ OraNumber
681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'ext/oci8/ocinumber.c', line 681 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); } |
.sin(x) ⇒ OraNumber
452 453 454 455 456 457 458 459 460 |
# File 'ext/oci8/ocinumber.c', line 452 static VALUE omath_sin(VALUE obj, VALUE radian) { OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; chkerr(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } |
.sinh(x) ⇒ OraNumber
582 583 584 585 586 587 588 589 590 |
# File 'ext/oci8/ocinumber.c', line 582 static VALUE omath_sinh(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; chkerr(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } |
.sqrt(x) ⇒ OraNumber
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'ext/oci8/ocinumber.c', line 704 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); } |
.tan(x) ⇒ OraNumber
470 471 472 473 474 475 476 477 478 |
# File 'ext/oci8/ocinumber.c', line 470 static VALUE omath_tan(VALUE obj, VALUE radian) { OCIError *errhp = oci8_errhp; OCINumber r; OCINumber rv; chkerr(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv)); return oci8_make_ocinumber(&rv, errhp); } |
.tanh(x) ⇒ OraNumber
600 601 602 603 604 605 606 607 608 |
# File 'ext/oci8/ocinumber.c', line 600 static VALUE omath_tanh(VALUE obj, VALUE num) { OCIError *errhp = oci8_errhp; OCINumber n; OCINumber r; chkerr(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r)); return oci8_make_ocinumber(&r, errhp); } |