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
-
.OCI8::Math.acos(x) ⇒ Object
Computes the arc cosine of x.
-
.OCI8::Math.asin(x) ⇒ Object
Computes the arc sine of x.
-
.OCI8::Math.atan(x) ⇒ Object
Computes the arc tangent of x.
-
.OCI8::Math.atan2(y, x) ⇒ Object
Computes the arc tangent given y and x.
-
.OCI8::Math.cos(x) ⇒ Object
Computes the cosine of x (expressed in radians).
-
.OCI8::Math.cosh(x) ⇒ Object
Computes the hyperbolic cosine of x (expressed in radians).
-
.OCI8::Math.exp(x) ⇒ Object
Returns e**x.
-
.log(*args) ⇒ Object
Returns the natural logarithm of numeric for one argument.
-
.OCI8::Math.log10(numeric) ⇒ Object
Returns the base 10 logarithm of numeric.
-
.OCI8::Math.sin(x) ⇒ Object
Computes the sine of x (expressed in radians).
-
.OCI8::Math.sinh(x) ⇒ Object
Computes the hyperbolic sine of x (expressed in radians).
-
.OCI8::Math.sqrt(numeric) ⇒ Object
Returns the non-negative square root of numeric.
-
.OCI8::Math.tan(x) ⇒ Object
Returns the tangent of x (expressed in radians).
-
.OCI8::Math.tanh ⇒ Object
Computes the hyperbolic tangent of x (expressed in radians).
Class Method Details
.OCI8::Math.acos(x) ⇒ Object
Computes the arc cosine of x. Returns 0..PI.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'ext/oci8/ocinumber.c', line 364
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 */
oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
if (sign > 0)
rb_raise(rb_eRangeError, "out of range for acos");
/* check lower bound */
oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
if (sign < 0)
rb_raise(rb_eRangeError, "out of range for acos");
/* acos */
oci_lc(OCINumberArcCos(errhp, &n, &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.asin(x) ⇒ Object
Computes the arc sine of x. Returns 0..PI.
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'ext/oci8/ocinumber.c', line 391
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 */
oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
if (sign > 0)
rb_raise(rb_eRangeError, "out of range for asin");
/* check lower bound */
oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
if (sign < 0)
rb_raise(rb_eRangeError, "out of range for asin");
/* asin */
oci_lc(OCINumberArcSin(errhp, &n, &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.atan(x) ⇒ Object
Computes the arc tangent of x. Returns -PI/2 .. PI/2.
418 419 420 421 422 423 424 425 426 |
# File 'ext/oci8/ocinumber.c', line 418
static VALUE omath_atan(VALUE obj, VALUE num)
{
OCIError *errhp = oci8_errhp;
OCINumber n;
OCINumber r;
oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.atan2(y, x) ⇒ Object
Computes the arc tangent given y and x. Returns -PI..PI.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'ext/oci8/ocinumber.c', line 279
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 */
oci_lc(OCINumberIsZero(errhp, &nX, &is_zero));
if (is_zero) {
oci_lc(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 */
oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv));
return oci8_make_ocinumber(&rv, errhp);
}
|
.OCI8::Math.cos(x) ⇒ Object
Computes the cosine of x (expressed in radians). Returns -1..1.
315 316 317 318 319 320 321 322 323 |
# File 'ext/oci8/ocinumber.c', line 315
static VALUE omath_cos(VALUE obj, VALUE radian)
{
OCIError *errhp = oci8_errhp;
OCINumber r;
OCINumber rv;
oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv));
return oci8_make_ocinumber(&rv, errhp);
}
|
.OCI8::Math.cosh(x) ⇒ Object
Computes the hyperbolic cosine of x (expressed in radians).
434 435 436 437 438 439 440 441 442 |
# File 'ext/oci8/ocinumber.c', line 434
static VALUE omath_cosh(VALUE obj, VALUE num)
{
OCIError *errhp = oci8_errhp;
OCINumber n;
OCINumber r;
oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.exp(x) ⇒ Object
Returns e**x.
484 485 486 487 488 489 490 491 492 |
# File 'ext/oci8/ocinumber.c', line 484
static VALUE omath_exp(VALUE obj, VALUE num)
{
OCIError *errhp = oci8_errhp;
OCINumber n;
OCINumber r;
oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.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.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'ext/oci8/ocinumber.c', line 502
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);
oci_lc(OCINumberSign(errhp, &n, &sign));
if (sign <= 0)
rb_raise(rb_eRangeError, "nonpositive value for log");
if (NIL_P(base)) {
oci_lc(OCINumberLn(errhp, &n, &r));
} else {
set_oci_number_from_num(&b, base, 1, errhp);
oci_lc(OCINumberSign(errhp, &b, &sign));
if (sign <= 0)
rb_raise(rb_eRangeError, "nonpositive value for the base of log");
oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign));
if (sign == 0)
rb_raise(rb_eRangeError, "base 1 for log");
oci_lc(OCINumberLog(errhp, &b, &n, &r));
}
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.log10(numeric) ⇒ Object
Returns the base 10 logarithm of numeric.
537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'ext/oci8/ocinumber.c', line 537
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);
oci_lc(OCINumberSign(errhp, &n, &sign));
if (sign <= 0)
rb_raise(rb_eRangeError, "nonpositive value for log10");
oci_lc(OCINumberLog(errhp, &const_p10, &n, &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.sin(x) ⇒ Object
Computes the sine of x (expressed in radians). Returns -1..1.
332 333 334 335 336 337 338 339 340 |
# File 'ext/oci8/ocinumber.c', line 332
static VALUE omath_sin(VALUE obj, VALUE radian)
{
OCIError *errhp = oci8_errhp;
OCINumber r;
OCINumber rv;
oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv));
return oci8_make_ocinumber(&rv, errhp);
}
|
.OCI8::Math.sinh(x) ⇒ Object
Computes the hyperbolic sine of x (expressed in radians).
451 452 453 454 455 456 457 458 459 |
# File 'ext/oci8/ocinumber.c', line 451
static VALUE omath_sinh(VALUE obj, VALUE num)
{
OCIError *errhp = oci8_errhp;
OCINumber n;
OCINumber r;
oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.sqrt(numeric) ⇒ Object
Returns the non-negative square root of numeric.
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'ext/oci8/ocinumber.c', line 558
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 */
oci_lc(OCINumberSign(errhp, &n, &sign));
if (sign < 0) {
errno = EDOM;
rb_sys_fail("sqrt");
}
oci_lc(OCINumberSqrt(errhp, &n, &r));
return oci8_make_ocinumber(&r, errhp);
}
|
.OCI8::Math.tan(x) ⇒ Object
Returns the tangent of x (expressed in radians).
348 349 350 351 352 353 354 355 356 |
# File 'ext/oci8/ocinumber.c', line 348
static VALUE omath_tan(VALUE obj, VALUE radian)
{
OCIError *errhp = oci8_errhp;
OCINumber r;
OCINumber rv;
oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv));
return oci8_make_ocinumber(&rv, errhp);
}
|
.OCI8::Math.tanh ⇒ Object
Computes the hyperbolic tangent of x (expressed in radians).
468 469 470 471 472 473 474 475 476 |
# File 'ext/oci8/ocinumber.c', line 468
static VALUE omath_tanh(VALUE obj, VALUE num)
{
OCIError *errhp = oci8_errhp;
OCINumber n;
OCINumber r;
oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r));
return oci8_make_ocinumber(&r, errhp);
}
|