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

Class Method Details

.acos(x) ⇒ OraNumber

Computes the principal value of the arc cosine of x.



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'ext/oci8/ocinumber.c', line 516

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

Computes the principal value of the arc sine of x.



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'ext/oci8/ocinumber.c', line 545

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

Computes the principal value of the arc tangent of their argument x.



574
575
576
577
578
579
580
581
582
# File 'ext/oci8/ocinumber.c', line 574

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

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.



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'ext/oci8/ocinumber.c', line 425

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

Computes the cosine of x, measured in radians.



462
463
464
465
466
467
468
469
470
# File 'ext/oci8/ocinumber.c', line 462

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

Computes the hyperbolic cosine of x.



592
593
594
595
596
597
598
599
600
# File 'ext/oci8/ocinumber.c', line 592

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

Computes the base- e exponential of x.



646
647
648
649
650
651
652
653
654
# File 'ext/oci8/ocinumber.c', line 646

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

Overloads:

  • .log(x) ⇒ OraNumber

    Computes the natural logarithm of x.

  • .log(x, y) ⇒ OraNumber

    Computes the base y logarithm of x.



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'ext/oci8/ocinumber.c', line 672

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

Computes the base 10 logarithm of x.



709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'ext/oci8/ocinumber.c', line 709

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

Computes the sine of x, measured in radians.



480
481
482
483
484
485
486
487
488
# File 'ext/oci8/ocinumber.c', line 480

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

Computes the hyperbolic sine of x.



610
611
612
613
614
615
616
617
618
# File 'ext/oci8/ocinumber.c', line 610

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

Computes the square root of x.



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'ext/oci8/ocinumber.c', line 732

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

Computes the tangent of x, measured in radians.



498
499
500
501
502
503
504
505
506
# File 'ext/oci8/ocinumber.c', line 498

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

Computes the hyperbolic tangent of x.



628
629
630
631
632
633
634
635
636
# File 'ext/oci8/ocinumber.c', line 628

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);
}