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

Class Method Details

.acos(z, prec) ⇒ BigDecimal, Complex

Computes inverse cosine of z.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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

Overloads:

  • .atan(z, prec) ⇒ BigDecimal, Complex

    Computes the inverse tangent z.

    Examples:

    BigMathR.atan(1, 20)
    #=> 0.78539816339744830963e0
    BigMathR.atan(1+1i, 20)
    #=> (0.10172219678978513677e1+0.40235947810852509365e0i)

    Parameters:

    • z (Numeric)

      Numerical argument

    • prec (Integer)

      Arbitrary precision

    Returns:

    • (BigDecimal)

      Real solution

    • (Complex)

      Complex solution

    Raises:

    • (ArgumentError)

      Occurs when prec is not a positive integer.

    • (TypeError)

      Occurs when z is not a numeric class.

    Since:

    • 0.1.0

  • .atan(z, w, prec) ⇒ BigDecimal, Complex

    Consider where the value is in quadrant XY and computes the inverse tangent of w/z.
    This function is equivalent to atan2(y, x), but the arguments are in a different order.

    Examples:

    BigMathR.atan(1, 2, 20)
    #=> 0.11071487177940905031e1
    BigMathR.atan(3i, 2i, 20)
    #=> (0.58800260354756755124e0+0i)

    Parameters:

    • z (Numeric)

      Numerical argument, as Quadrant XY of X

    • w (Numeric)

      Numerical argument, as Quadrant XY of Y

    • prec (Integer)

      Arbitrary precision

    Returns:

    • (BigDecimal)

      Real solution

    • (Complex)

      Complex solution

    Raises:

    • (ArgumentError)

      Occurs when prec is not a positive integer.

    • (TypeError)

      Occurs when z or w is not a numeric class.

    Since:

    • 0.1.0



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.

Parameters:

  • y (Numeric)

    Y-axis

  • x (Numeric)

    X-axis

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when x is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Examples:

BigMathR.cbrt(-1, 20)
#=> -0.1e1
BigMathR.cbrt(-1+0i, 20)
#=> (0.49999999999999999999e0+0.86602540378443864677e0i)

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.2.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Examples:

BigMathR.E(20) #=> 0.27182818284590452354e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Examples:

BigMathR.erf(5, 20)
#=> 0.99999999999846254021e0
BigMathR.erf(5, 40)
#=> 0.9999999999984625402055719651498116565146e0

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.2.1



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.

Examples:

BigMathR.erfc(5, 20)
#=> 0.153745979e-11
BigMathR.erfc(5, 40)
#=> 0.15374597944280348501883434854e-11

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.2.1



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.

Examples:

BigMathR.EulerGamma(20) #=>

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • a (Numeric)

    adjacent side or opposite side

  • b (Numeric)

    adjacent side or opposite side

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when x is not a numeric class.

Since:

  • 0.1.0



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

Overloads:

  • .log(z, prec) ⇒ BigDecimal, Complex

    Computes the Natural logarithm of z.

    Parameters:

    • z (Numeric)

      Numerical argument

    • prec (Integer)

      Arbitrary precision

    Returns:

    • (BigDecimal)

      Real solution

    • (Complex)

      Complex solution

    Raises:

    • (ArgumentError)

      Occurs when prec is not a positive integer.

    • (TypeError)

      Occurs when z is not a numeric class.

    Since:

    • 0.1.0

  • .log(z, b, prec) ⇒ BigDecimal, Complex

    Computes the Natural logarithm of z on base b.

    Parameters:

    • z (Numeric)

      Numerical argument

    • b (Numeric)

      The base. Specified a real number

    • prec (Integer)

      Arbitrary precision

    Returns:

    • (BigDecimal)

      Real solution

    • (Complex)

      Complex solution

    Raises:

    • (ArgumentError)

      Occurs when prec is not a positive integer.

    • (TypeError)

      Occurs when z is not a numeric class.

    Since:

    • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Examples:

BigMathR.LOG10(20) #=> 0.2302585092994045684e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Examples:

BigMathR.LOG2(20) #=> 0.69314718055994530942e0

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Examples:

BigMathR.LOG_PI(20) #=> 0.11447298858494001741e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Examples:

BigMathR.PI(20) #=> 0.314159265358979323846e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Examples:

BigMathR.sqrt(-1, 20) == Complex::I
#=> true
BigMathR.sqrt(2, 20)
#=> 0.14142135623730950488e1
BigMathR.sqrt(1+1i, 20)
#=> (0.109868411346780996604e1+0.4550898605622273413e0i)

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.2.0



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.

Examples:

BigMathR.SQRT2(20) #=> 0.14142135623730950488e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Examples:

BigMathR.SQRT3(20) #=> 0.17320508075688772935e1

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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.

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution

Raises:

  • (ArgumentError)

    Occurs when prec is not a positive integer.

  • (TypeError)

    Occurs when z is not a numeric class.

Since:

  • 0.1.0



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