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.

Parameters:

Returns:



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'ext/oci8/ocinumber.c', line 486

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.

Parameters:

Returns:



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

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.

Parameters:

Returns:



544
545
546
547
548
549
550
551
552
# File 'ext/oci8/ocinumber.c', line 544

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.

Parameters:

Returns:



395
396
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
# File 'ext/oci8/ocinumber.c', line 395

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.

Parameters:

Returns:

  • (OraNumber)

    Computed value in the range [-1, 1]



432
433
434
435
436
437
438
439
440
# File 'ext/oci8/ocinumber.c', line 432

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.

Parameters:

Returns:



562
563
564
565
566
567
568
569
570
# File 'ext/oci8/ocinumber.c', line 562

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.

Parameters:

Returns:



616
617
618
619
620
621
622
623
624
# File 'ext/oci8/ocinumber.c', line 616

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:



642
643
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
# File 'ext/oci8/ocinumber.c', line 642

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.

Parameters:

Returns:



679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'ext/oci8/ocinumber.c', line 679

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.

Parameters:

Returns:

  • (OraNumber)

    Computed value in the range [-1, 1]



450
451
452
453
454
455
456
457
458
# File 'ext/oci8/ocinumber.c', line 450

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.

Parameters:

Returns:



580
581
582
583
584
585
586
587
588
# File 'ext/oci8/ocinumber.c', line 580

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.

Parameters:

Returns:



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'ext/oci8/ocinumber.c', line 702

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.

Parameters:

Returns:



468
469
470
471
472
473
474
475
476
# File 'ext/oci8/ocinumber.c', line 468

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.

Parameters:

Returns:



598
599
600
601
602
603
604
605
606
# File 'ext/oci8/ocinumber.c', line 598

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