Module: BigMathR
- Defined in:
- ext/bigdecimal/math_r/math_r.c,
lib/bigdecimal/math_r/version.rb,
lib/bigdecimal/math_r/const/E_euler.rb,
lib/bigdecimal/math_r/const/PI_euler.rb,
lib/bigdecimal/math_r/const/LOG2_bbp2007.rb,
lib/bigdecimal/math_r/const/PI_chudnovsky.rb,
lib/bigdecimal/math_r/const/PI_ramanujan1.rb,
lib/bigdecimal/math_r/const/PI_ramanujan2.rb,
lib/bigdecimal/math_r/const/EulerGamma_engel.rb,
ext/bigdecimal/math_r/math_r.c
Overview
Refined BigMath module. It is a total solution for mathematics that also supports complex numbers.
- Reference
-
Utsukusii Suugaku wo egaku π, e, to Euler no teisuu γ (Japanese) - WAKAHARA Tatsuhiko (Kohdan-sha Editorial)
Defined Under Namespace
Modules: ComplexPlane, Const, EDF, Erf, EulerF, Exp, GammaBeta, Hyperb, Log, LogRep, Logarithm, Power, Solver, Trig
Constant Summary collapse
- VERSION =
Module version.
"0.2.8"
Class Method Summary collapse
-
.acos(z, prec) ⇒ BigDecimal, Complex
Computes inverse cosine of
z. -
.acosh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cosine of
z. -
.acot(z, prec) ⇒ BigDecimal, Complex
Computes inverse cotangent of
z. -
.acoth(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cotangent of
z. -
.acsc(z, prec) ⇒ BigDecimal, Complex
Computes inverse cosecant of
z. -
.acsch(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cosecant of
z. -
.asec(z, prec) ⇒ BigDecimal, Complex
Computes inverse secant of
z. -
.asech(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic secant of
z. -
.asin(z, prec) ⇒ BigDecimal, Complex
Computes inverse sine of
z. -
.asinh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic sine of
z. - .atan(*args) ⇒ Object
-
.atan2(y, x, prec) ⇒ BigDecimal, Complex
Consider where the value is in quadrant XY and computes the inverse tangent of
y/x. -
.atanh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic tangent of
z. -
.cbrt(z, prec) ⇒ BigDecimal, Complex
Computes cubic root of
z. -
.cos(z, prec) ⇒ BigDecimal, Complex
Computes cosine of
z. -
.cosh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cosine of
z. -
.cot(z, prec) ⇒ BigDecimal, Complex
Computes cotangent of
z. -
.coth(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cotangent of
z. -
.csc(z, prec) ⇒ BigDecimal, Complex
Computes cosecant of
z. -
.csch(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cosecant of
z. -
.E(prec) ⇒ BigDecimal
The constant e.
-
.erf(z, prec) ⇒ BigDecimal
Computes error function of
z. -
.erfc(z, prec) ⇒ BigDecimal
Computes complementary error function of
z. -
.EulerGamma(prec) ⇒ BigDecimal
The Euler-Mascheroni constant gamma.
-
.exp(z, prec) ⇒ BigDecimal, Complex
Computes exponential function of
z. -
.exp2(z, prec) ⇒ BigDecimal, Complex
Computes base-2 (binary) exponent of
z. -
.hypot(a, b, prec) ⇒ BigDecimal
Returns the hypotenuse of a right triangle with side lengths of
aandb. - .log(*args) ⇒ Object
-
.log10(z, prec) ⇒ BigDecimal, Complex
Computes common logarithm of
z. -
.LOG10(prec) ⇒ BigDecimal
The natural logarithm of 10.
-
.log1p(z, prec) ⇒ BigDecimal, Complex
Computes natural logarithm of 1 plus
z. -
.log2(z, prec) ⇒ BigDecimal, Complex
Computes binary logarithm of
z. -
.LOG2(prec) ⇒ BigDecimal
The natural logarithm of 2.
-
.LOG_PI(prec) ⇒ BigDecimal
The natural logarithm of pi.
-
.PI(prec) ⇒ BigDecimal
The constant pi.
-
.sec(z, prec) ⇒ BigDecimal, Complex
Computes secant of
z. -
.sech(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic secant of
z. -
.sin(z, prec) ⇒ BigDecimal, Complex
Computes sine of
z. -
.sinh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic sine of
z. -
.sqrt(z, prec) ⇒ BigDecimal, Complex
Computes square root of
z. -
.SQRT2(prec) ⇒ BigDecimal
The square root of 2.
-
.SQRT3(prec) ⇒ BigDecimal
The square root of 3.
-
.tan(z, prec) ⇒ BigDecimal, Complex
Computes tangent of
z. -
.tanh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic tangent of
z.
Class Method Details
.acos(z, prec) ⇒ BigDecimal, Complex
Computes inverse cosine of z.
975 976 977 978 979 |
# File 'ext/bigdecimal/math_r/solver.c', line 975
static VALUE
__impl_bigmath_acos(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_triginv(mf_acos, z, prec);
}
|
.acosh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cosine of z.
1242 1243 1244 1245 1246 |
# File 'ext/bigdecimal/math_r/solver.c', line 1242
static VALUE
__impl_bigmath_acosh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_acosh, z, prec);
}
|
.acot(z, prec) ⇒ BigDecimal, Complex
Computes inverse cotangent of z.
1083 1084 1085 1086 1087 |
# File 'ext/bigdecimal/math_r/solver.c', line 1083
static VALUE
__impl_bigmath_acot(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_triginv(mf_acot, z, prec);
}
|
.acoth(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cotangent of z.
1310 1311 1312 1313 1314 |
# File 'ext/bigdecimal/math_r/solver.c', line 1310
static VALUE
__impl_bigmath_acoth(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_acoth, z, prec);
}
|
.acsc(z, prec) ⇒ BigDecimal, Complex
Computes inverse cosecant of z.
1049 1050 1051 1052 1053 |
# File 'ext/bigdecimal/math_r/solver.c', line 1049
static VALUE
__impl_bigmath_acsc(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_triginv(mf_acsc, z, prec);
}
|
.acsch(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic cosecant of z.
1276 1277 1278 1279 1280 |
# File 'ext/bigdecimal/math_r/solver.c', line 1276
static VALUE
__impl_bigmath_acsch(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_acsch, z, prec);
}
|
.asec(z, prec) ⇒ BigDecimal, Complex
Computes inverse secant of z.
1066 1067 1068 1069 1070 |
# File 'ext/bigdecimal/math_r/solver.c', line 1066
static VALUE
__impl_bigmath_asec(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_triginv(mf_asec, z, prec);
}
|
.asech(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic secant of z.
1293 1294 1295 1296 1297 |
# File 'ext/bigdecimal/math_r/solver.c', line 1293
static VALUE
__impl_bigmath_asech(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_asech, z, prec);
}
|
.asin(z, prec) ⇒ BigDecimal, Complex
Computes inverse sine of z.
958 959 960 961 962 |
# File 'ext/bigdecimal/math_r/solver.c', line 958
static VALUE
__impl_bigmath_asin(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_triginv(mf_asin, z, prec);
}
|
.asinh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic sine of z.
1225 1226 1227 1228 1229 |
# File 'ext/bigdecimal/math_r/solver.c', line 1225
static VALUE
__impl_bigmath_asinh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_asinh, z, prec);
}
|
.atan(z, prec) ⇒ BigDecimal, Complex .atan(z, w, prec) ⇒ BigDecimal, Complex
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
# File 'ext/bigdecimal/math_r/solver.c', line 1014
static VALUE
__impl_bigmath_atan(int argc, VALUE *argv, VALUE unused_obj)
{
VALUE z = Qundef, w = Qundef, prec = Qundef;
rb_check_arity(argc, 2, 3);
switch (argc) {
case 2:
rb_scan_args(argc, argv, "20", &z, &prec);
CHECK_NUMARG(z);
rb_check_precise(prec);
z = solver_triginv(mf_atan, z, prec);
break;
case 3:
rb_scan_args(argc, argv, "30", &z, &w, &prec);
CHECK_NUMARG(z);
CHECK_NUMARG(w);
rb_check_precise(prec);
z = rb_bigmath_quadrant(z, w, prec);
break;
}
return z;
}
|
.atan2(y, x, prec) ⇒ BigDecimal, Complex
Consider where the value is in quadrant XY and computes the inverse tangent of y/x.
109 110 111 112 113 |
# File 'ext/bigdecimal/math_r/nucomp.c', line 109
static VALUE
__impl_bigmathr_atan2(VALUE unused_obj, VALUE y, VALUE x, VALUE prec)
{
return rb_bigmath_quadrant(x, y, prec);
}
|
.atanh(z, prec) ⇒ BigDecimal, Complex
Computes inverse hyperbolic tangent of z.
1259 1260 1261 1262 1263 |
# File 'ext/bigdecimal/math_r/solver.c', line 1259
static VALUE
__impl_bigmath_atanh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperbinv(mf_atanh, z, prec);
}
|
.cbrt(z, prec) ⇒ BigDecimal, Complex
Computes cubic root of z.
Note that the return value differs depending on the type of the argument.
For example, a negative argument returns a different value for real and complex solutions.
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 |
# File 'ext/bigdecimal/math_r/solver.c', line 1374
static VALUE
__impl_bigmath_cbrt(VALUE unused_obj, VALUE z, VALUE prec)
{
VALUE w = Qundef;
if (rb_num_real_p(z))
{
z = rb_num_canonicalize(z, prec, ARG_REAL, ARG_RAWVALUE);
w = cb_cbrt(z, prec);
}
else
{
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
w = cb_ccbrt(z, prec);
}
return w;
}
|
.cos(z, prec) ⇒ BigDecimal, Complex
Computes cosine of z.
547 548 549 550 551 |
# File 'ext/bigdecimal/math_r/solver.c', line 547
static VALUE
__impl_bigmath_cos(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_cos, z, prec);
}
|
.cosh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cosine of z.
764 765 766 767 768 |
# File 'ext/bigdecimal/math_r/solver.c', line 764
static VALUE
__impl_bigmath_cosh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_cosh, z, prec);
}
|
.cot(z, prec) ⇒ BigDecimal, Complex
Computes cotangent of z.
615 616 617 618 619 |
# File 'ext/bigdecimal/math_r/solver.c', line 615
static VALUE
__impl_bigmath_cot(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_cot, z, prec);
}
|
.coth(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cotangent of z.
832 833 834 835 836 |
# File 'ext/bigdecimal/math_r/solver.c', line 832
static VALUE
__impl_bigmath_coth(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_coth, z, prec);
}
|
.csc(z, prec) ⇒ BigDecimal, Complex
Computes cosecant of z.
581 582 583 584 585 |
# File 'ext/bigdecimal/math_r/solver.c', line 581
static VALUE
__impl_bigmath_csc(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_csc, z, prec);
}
|
.csch(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic cosecant of z.
798 799 800 801 802 |
# File 'ext/bigdecimal/math_r/solver.c', line 798
static VALUE
__impl_bigmath_csch(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_csch, z, prec);
}
|
.E(prec) ⇒ BigDecimal
The constant e.
51 52 53 54 55 |
# File 'ext/bigdecimal/math_r/const.c', line 51
static VALUE
__impl_const_e(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_e(prec);
}
|
.erf(z, prec) ⇒ BigDecimal
Computes error function of z.
1406 1407 1408 1409 1410 |
# File 'ext/bigdecimal/math_r/solver.c', line 1406
static VALUE
__impl_bigmath_erf(VALUE unused_obj, VALUE z, VALUE prec)
{
return erf_branch(z, prec, cb_erf);
}
|
.erfc(z, prec) ⇒ BigDecimal
Computes complementary error function of z.
1427 1428 1429 1430 1431 |
# File 'ext/bigdecimal/math_r/solver.c', line 1427
static VALUE
__impl_bigmath_erfc(VALUE unused_obj, VALUE z, VALUE prec)
{
return erfc_branch(z, prec, cb_erfc);
}
|
.EulerGamma(prec) ⇒ BigDecimal
The Euler-Mascheroni constant gamma.
66 67 68 69 70 |
# File 'ext/bigdecimal/math_r/const.c', line 66
static VALUE
__impl_const_euler_gamma(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_euler_gamma(prec);
}
|
.exp(z, prec) ⇒ BigDecimal, Complex
Computes exponential function of z.
195 196 197 198 199 |
# File 'ext/bigdecimal/math_r/solver.c', line 195
static VALUE
__impl_bigmath_exp(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_exp(mf_exp, z, prec);
}
|
.exp2(z, prec) ⇒ BigDecimal, Complex
Computes base-2 (binary) exponent of z.
212 213 214 215 216 |
# File 'ext/bigdecimal/math_r/solver.c', line 212
static VALUE
__impl_bigmath_exp2(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_exp(mf_exp2, z, prec);
}
|
.hypot(a, b, prec) ⇒ BigDecimal
Returns the hypotenuse of a right triangle with side lengths of a and b.
The return value will definitely be a positive real number.
It is implemented by the norm, so even if the argument is a complex number, it will be a positive real number.
56 57 58 59 60 |
# File 'ext/bigdecimal/math_r/nucomp.c', line 56
static VALUE
__impl_bigmathr_hypot(VALUE unused_obj, VALUE a, VALUE b, VALUE prec)
{
return rb_bigmath_hypot(a, b, prec);
}
|
.log(z, prec) ⇒ BigDecimal, Complex .log(z, b, prec) ⇒ BigDecimal, Complex
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/bigdecimal/math_r/solver.c', line 309
static VALUE
__impl_bigmath_log(int argc, VALUE *argv, VALUE unused_obj)
{
VALUE z = Qundef, b = Qundef, prec = Qundef;
rb_check_arity(argc, 2, 3);
switch (argc) {
case 2:
rb_scan_args(argc, argv, "20", &z, &prec);
z = solver_log(mf_log, z, prec);
break;
case 3:
rb_scan_args(argc, argv, "30", &z, &b, &prec);
rb_check_precise(prec);
CHECK_NUMARG(z);
b = rb_num_canonicalize(b, prec, ARG_REAL, ARG_RAWVALUE);
if (rb_num_nan_p(b))
z = rb_num_real_p(z) && !rb_num_negative_p(z) ?
BIG_NAN : rb_Complex(BIG_NAN, BIG_NAN);
else if (rb_num_infinite_p(b))
z = rb_num_real_p(z) && !rb_num_negative_p(z) ?
BIG_ZERO : rb_Complex(BIG_ZERO, BIG_ZERO);
else if (rb_num_zero_p(b))
z = rb_num_zero_p(z) ?
rb_num_real_p(z) ?
BIG_NAN :
rb_Complex(BIG_NAN, BIG_NAN) :
rb_num_real_p(z) && !rb_num_negative_p(z) ?
BIG_ZERO :
rb_Complex(BIG_ZERO, BIG_ZERO);
else if (rb_num_equal_p(b, BIG_ONE))
z = rb_Complex(BIG_INF, BIG_INF);
else
{
z = solver_log(mf_log, z, prec);
b = solver_log(mf_log, b, prec);
z = rb_funcall1(z, '/', b);
z = rb_num_round(z, prec);
}
break;
}
return z;
}
|
.log10(z, prec) ⇒ BigDecimal, Complex
Computes common logarithm of z.
398 399 400 401 402 |
# File 'ext/bigdecimal/math_r/solver.c', line 398
static VALUE
__impl_bigmath_log10(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_log(mf_log10, z, prec);
}
|
.LOG10(prec) ⇒ BigDecimal
The natural logarithm of 10.
96 97 98 99 100 |
# File 'ext/bigdecimal/math_r/const.c', line 96
static VALUE
__impl_const_log10(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_log10(prec);
}
|
.log1p(z, prec) ⇒ BigDecimal, Complex
Computes natural logarithm of 1 plus z.
364 365 366 367 368 |
# File 'ext/bigdecimal/math_r/solver.c', line 364
static VALUE
__impl_bigmath_log1p(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_log(mf_log1p, z, prec);
}
|
.log2(z, prec) ⇒ BigDecimal, Complex
Computes binary logarithm of z.
381 382 383 384 385 |
# File 'ext/bigdecimal/math_r/solver.c', line 381
static VALUE
__impl_bigmath_log2(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_log(mf_log2, z, prec);
}
|
.LOG2(prec) ⇒ BigDecimal
The natural logarithm of 2.
81 82 83 84 85 |
# File 'ext/bigdecimal/math_r/const.c', line 81
static VALUE
__impl_const_log2(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_log2(prec);
}
|
.LOG_PI(prec) ⇒ BigDecimal
The natural logarithm of pi.
36 37 38 39 40 |
# File 'ext/bigdecimal/math_r/const.c', line 36
static VALUE
__impl_const_log_pi(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_log_pi(prec);
}
|
.PI(prec) ⇒ BigDecimal
The constant pi.
21 22 23 24 25 |
# File 'ext/bigdecimal/math_r/const.c', line 21
static VALUE
__impl_const_pi(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_pi(prec);
}
|
.sec(z, prec) ⇒ BigDecimal, Complex
Computes secant of z.
598 599 600 601 602 |
# File 'ext/bigdecimal/math_r/solver.c', line 598
static VALUE
__impl_bigmath_sec(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_sec, z, prec);
}
|
.sech(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic secant of z.
815 816 817 818 819 |
# File 'ext/bigdecimal/math_r/solver.c', line 815
static VALUE
__impl_bigmath_sech(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_sech, z, prec);
}
|
.sin(z, prec) ⇒ BigDecimal, Complex
Computes sine of z.
530 531 532 533 534 |
# File 'ext/bigdecimal/math_r/solver.c', line 530
static VALUE
__impl_bigmath_sin(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_sin, z, prec);
}
|
.sinh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic sine of z.
747 748 749 750 751 |
# File 'ext/bigdecimal/math_r/solver.c', line 747
static VALUE
__impl_bigmath_sinh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_sinh, z, prec);
}
|
.sqrt(z, prec) ⇒ BigDecimal, Complex
Computes square root of z.
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 |
# File 'ext/bigdecimal/math_r/solver.c', line 1334
static VALUE
__impl_bigmath_sqrt(VALUE unused_obj, VALUE z, VALUE prec)
{
VALUE w = Qundef;
if (rb_num_real_p(z))
{
z = rb_num_canonicalize(z, prec, ARG_REAL, ARG_RAWVALUE);
if (rb_num_negative_p(z))
w = sqrt_edom(z, prec);
else
w = cb_sqrt(z, prec);
}
else
{
z = rb_num_canonicalize(z, prec, ARG_COMPLEX, ARG_RAWVALUE);
w = cb_csqrt(z, prec);
}
return w;
}
|
.SQRT2(prec) ⇒ BigDecimal
The square root of 2.
111 112 113 114 115 |
# File 'ext/bigdecimal/math_r/const.c', line 111
static VALUE
__impl_const_sqrt2(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_sqrt2(prec);
}
|
.SQRT3(prec) ⇒ BigDecimal
The square root of 3.
126 127 128 129 130 |
# File 'ext/bigdecimal/math_r/const.c', line 126
static VALUE
__impl_const_sqrt3(VALUE unused_obj, VALUE prec)
{
return rb_bigmath_const_sqrt3(prec);
}
|
.tan(z, prec) ⇒ BigDecimal, Complex
Computes tangent of z.
564 565 566 567 568 |
# File 'ext/bigdecimal/math_r/solver.c', line 564
static VALUE
__impl_bigmath_tan(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_trig(mf_tan, z, prec);
}
|
.tanh(z, prec) ⇒ BigDecimal, Complex
Computes hyperbolic tangent of z.
781 782 783 784 785 |
# File 'ext/bigdecimal/math_r/solver.c', line 781
static VALUE
__impl_bigmath_tanh(VALUE unused_obj, VALUE z, VALUE prec)
{
return solver_hyperb(mf_tanh, z, prec);
}
|