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
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'ext/oci8/ocinumber.c', line 501
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
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'ext/oci8/ocinumber.c', line 530
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
559 560 561 562 563 564 565 566 567 |
# File 'ext/oci8/ocinumber.c', line 559
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
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'ext/oci8/ocinumber.c', line 410
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
447 448 449 450 451 452 453 454 455 |
# File 'ext/oci8/ocinumber.c', line 447
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
577 578 579 580 581 582 583 584 585 |
# File 'ext/oci8/ocinumber.c', line 577
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
631 632 633 634 635 636 637 638 639 |
# File 'ext/oci8/ocinumber.c', line 631
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
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'ext/oci8/ocinumber.c', line 657
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
694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'ext/oci8/ocinumber.c', line 694
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
465 466 467 468 469 470 471 472 473 |
# File 'ext/oci8/ocinumber.c', line 465
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
595 596 597 598 599 600 601 602 603 |
# File 'ext/oci8/ocinumber.c', line 595
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
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
# File 'ext/oci8/ocinumber.c', line 717
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
483 484 485 486 487 488 489 490 491 |
# File 'ext/oci8/ocinumber.c', line 483
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
613 614 615 616 617 618 619 620 621 |
# File 'ext/oci8/ocinumber.c', line 613
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);
}
|