Module: OCI8::Math

Defined in:
ext/oci8/ocinumber.c

Constant Summary collapse

PI =

The ratio of the circumference of a circle to its diameter.

obj_PI

Class Method Summary collapse

Class Method Details

.OCI8::Math.acos(x) ⇒ Object

Computes the arc cosine of x. Returns 0..PI.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'ext/oci8/ocinumber.c', line 287

static VALUE omath_acos(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;
    sword sign;

    set_oci_number_from_num(&n, num, 1);
    /* check upper bound */
    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
    if (sign > 0)
        rb_raise(rb_eRangeError, "out of range for acos");
    /* check lower bound */
    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
    if (sign < 0)
        rb_raise(rb_eRangeError, "out of range for acos");
    /* acos */
    oci_lc(OCINumberArcCos(oci8_errhp, &n, &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.asin(x) ⇒ Object

Computes the arc sine of x. Returns 0..PI.



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'ext/oci8/ocinumber.c', line 313

static VALUE omath_asin(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;
    sword sign;

    set_oci_number_from_num(&n, num, 1);
    /* check upper bound */
    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_p1, &sign));
    if (sign > 0)
        rb_raise(rb_eRangeError, "out of range for asin");
    /* check lower bound */
    oci_lc(OCINumberCmp(oci8_errhp, &n, &const_m1, &sign));
    if (sign < 0)
        rb_raise(rb_eRangeError, "out of range for asin");
    /* asin */
    oci_lc(OCINumberArcSin(oci8_errhp, &n, &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.atan(x) ⇒ Object

Computes the arc tangent of x. Returns -PI/2 .. PI/2.



339
340
341
342
343
344
345
346
# File 'ext/oci8/ocinumber.c', line 339

static VALUE omath_atan(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;

    oci_lc(OCINumberArcTan(oci8_errhp, TO_OCINUM(&n, num), &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.atan2(y, x) ⇒ Object

Computes the arc tangent given y and x. Returns -PI..PI.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'ext/oci8/ocinumber.c', line 206

static VALUE omath_atan2(VALUE self, VALUE Ycoordinate, VALUE Xcoordinate)
{
    OCINumber nY;
    OCINumber nX;
    OCINumber rv;
    boolean is_zero;
    sword sign;

    set_oci_number_from_num(&nX, Xcoordinate, 1);
    set_oci_number_from_num(&nY, Ycoordinate, 1);
    /* check zero */
    oci_lc(OCINumberIsZero(oci8_errhp, &nX, &is_zero));
    if (is_zero) {
        oci_lc(OCINumberSign(oci8_errhp, &nY, &sign));
        switch (sign) {
        case 0:
            return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */
        case 1:
            return oci8_make_ocinumber(&const_PI2); /* atan2(positive, 0) => PI/2 */
        case -1:
            return oci8_make_ocinumber(&const_mPI2); /* atan2(negative, 0) => -PI/2 */
        }
    }
    /* atan2 */
    oci_lc(OCINumberArcTan2(oci8_errhp, &nY, &nX, &rv));
    return oci8_make_ocinumber(&rv);
}

.OCI8::Math.cos(x) ⇒ Object

Computes the cosine of x (expressed in radians). Returns -1..1.



241
242
243
244
245
246
247
248
# File 'ext/oci8/ocinumber.c', line 241

static VALUE omath_cos(VALUE obj, VALUE radian)
{
    OCINumber r;
    OCINumber rv;

    oci_lc(OCINumberCos(oci8_errhp, TO_OCINUM(&r, radian), &rv));
    return oci8_make_ocinumber(&rv);
}

.OCI8::Math.cosh(x) ⇒ Object

Computes the hyperbolic cosine of x (expressed in radians).



354
355
356
357
358
359
360
361
# File 'ext/oci8/ocinumber.c', line 354

static VALUE omath_cosh(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;

    oci_lc(OCINumberHypCos(oci8_errhp, TO_OCINUM(&n, num), &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.exp(x) ⇒ Object

Returns e**x.



401
402
403
404
405
406
407
408
# File 'ext/oci8/ocinumber.c', line 401

static VALUE omath_exp(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;

    oci_lc(OCINumberExp(oci8_errhp, TO_OCINUM(&n, num), &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.log(numeric) ⇒ Object .OCI8::Math.log(numeric, base_num) ⇒ Object

Returns the natural logarithm of numeric for one argument. Returns the base base_num logarithm of numeric for two arguments.



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'ext/oci8/ocinumber.c', line 418

static VALUE omath_log(int argc, VALUE *argv, VALUE obj)
{
    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);
    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
    if (sign <= 0)
        rb_raise(rb_eRangeError, "nonpositive value for log");
    if (NIL_P(base)) {
        oci_lc(OCINumberLn(oci8_errhp, &n, &r));
    } else {
        set_oci_number_from_num(&b, base, 1);
        oci_lc(OCINumberSign(oci8_errhp, &b, &sign));
        if (sign <= 0)
            rb_raise(rb_eRangeError, "nonpositive value for the base of log");
        oci_lc(OCINumberCmp(oci8_errhp, &b, &const_p1, &sign));
        if (sign == 0)
            rb_raise(rb_eRangeError, "base 1 for log");
        oci_lc(OCINumberLog(oci8_errhp, &b, &n, &r));
    }
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.log10(numeric) ⇒ Object

Returns the base 10 logarithm of numeric.



452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'ext/oci8/ocinumber.c', line 452

static VALUE omath_log10(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;
    sword sign;

    set_oci_number_from_num(&n, num, 1);
    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
    if (sign <= 0)
        rb_raise(rb_eRangeError, "nonpositive value for log10");
    oci_lc(OCINumberLog(oci8_errhp, &const_p10, &n, &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.sin(x) ⇒ Object

Computes the sine of x (expressed in radians). Returns -1..1.



257
258
259
260
261
262
263
264
# File 'ext/oci8/ocinumber.c', line 257

static VALUE omath_sin(VALUE obj, VALUE radian)
{
    OCINumber r;
    OCINumber rv;

    oci_lc(OCINumberSin(oci8_errhp, TO_OCINUM(&r, radian), &rv));
    return oci8_make_ocinumber(&rv);
}

.OCI8::Math.sinh(x) ⇒ Object

Computes the hyperbolic sine of x (expressed in radians).



370
371
372
373
374
375
376
377
# File 'ext/oci8/ocinumber.c', line 370

static VALUE omath_sinh(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;

    oci_lc(OCINumberHypSin(oci8_errhp, TO_OCINUM(&n, num), &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.sqrt(numeric) ⇒ Object

Returns the non-negative square root of numeric.



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'ext/oci8/ocinumber.c', line 472

static VALUE omath_sqrt(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;
    sword sign;

    set_oci_number_from_num(&n, num, 1);
    /* check whether num is negative */
    oci_lc(OCINumberSign(oci8_errhp, &n, &sign));
    if (sign < 0) {
        errno = EDOM;
        rb_sys_fail("sqrt");
    }
    oci_lc(OCINumberSqrt(oci8_errhp, &n, &r));
    return oci8_make_ocinumber(&r);
}

.OCI8::Math.tan(x) ⇒ Object

Returns the tangent of x (expressed in radians).



272
273
274
275
276
277
278
279
# File 'ext/oci8/ocinumber.c', line 272

static VALUE omath_tan(VALUE obj, VALUE radian)
{
    OCINumber r;
    OCINumber rv;

    oci_lc(OCINumberTan(oci8_errhp, TO_OCINUM(&r, radian), &rv));
    return oci8_make_ocinumber(&rv);
}

.OCI8::Math.tanhObject

Computes the hyperbolic tangent of x (expressed in radians).



386
387
388
389
390
391
392
393
# File 'ext/oci8/ocinumber.c', line 386

static VALUE omath_tanh(VALUE obj, VALUE num)
{
    OCINumber n;
    OCINumber r;

    oci_lc(OCINumberHypTan(oci8_errhp, TO_OCINUM(&n, num), &r));
    return oci8_make_ocinumber(&r);
}