Module: BigMathR::Log

Defined in:
ext/bigdecimal/math_r/math_r.c

Class Method Summary collapse

Class Method Details

.clog10_formula(z, prec) ⇒ Complex

Computes complex common logarithm of z.

Examples:

BigMathR::LogSqrt.clog10(1+1i, 20)
#=> (0.15051499783199059761e0+0.34109408846046033688e0i)

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



220
221
222
223
224
# File 'ext/bigdecimal/math_r/log.c', line 220

static VALUE
__impl_clog10_formula(VALUE unused_obj, VALUE z, VALUE prec)
{
  return clog10_branch(z, prec, clog10_formula);
}

.clog2_formula(z, prec) ⇒ Complex

Computes complex binary logarithm of z.

Examples:

BigMathR::LogSqrt.clog2(1+1i, 20)
#=> (0.5e0+0.11330900354567984524e1i)

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



201
202
203
204
205
# File 'ext/bigdecimal/math_r/log.c', line 201

static VALUE
__impl_clog2_formula(VALUE unused_obj, VALUE z, VALUE prec)
{
  return clog2_branch(z, prec, clog2_formula);
}

.clog_formula(z, prec) ⇒ Complex

Computes complex natural logarithm of z.

Examples:

BigMathR::LogSqrt.clog(1+1i, 20)
#=> (0.34657359027997265471e0+0.78539816339744830963e0i)

Parameters:

  • z (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



182
183
184
185
186
# File 'ext/bigdecimal/math_r/log.c', line 182

static VALUE
__impl_clog_formula(VALUE unused_obj, VALUE z, VALUE prec)
{
  return clog_branch(z, prec, clog_formula);
}

.log10_edf(x, prec) ⇒ BigDecimal

Computes common logarithm of x.
In terms of solving real number solutions, the implementation is the same as log10() in C.

Examples:

BigMathR::EDF.log10(2, 30) #=> 0.301029995663981195213738894724e0

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number



163
164
165
166
167
# File 'ext/bigdecimal/math_r/log.c', line 163

static VALUE
__impl_log10_edf(VALUE unused_obj, VALUE x, VALUE prec)
{
  return log10_branch(x, prec, log10_edf);
}

.log1p_p_adic(x, prec) ⇒ Complex

Computes p-adic logarithm of x.

Examples:

BigMathR::Log.log1p_p_adic(1, 20)
#=> 0.69314718055994530942e0

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'ext/bigdecimal/math_r/log.c', line 56

static VALUE
__impl_log1p_p_adic(VALUE uunused_obj, VALUE x, VALUE prec)
{
  const ID cover_p = rb_intern("cover?");
  VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), false);
  if (RTEST(rb_funcall(domain, cover_p, 1, x)))
  {
    if (rb_num_equal_p(x, INT2FIX(-1)))
      return BIG_MINUS_INF;
    else if (rb_num_equal_p(x, INT2FIX(1)))
      return rb_bigmath_const_log2(prec);
    else
      return log1p_p_adic(x, prec);
  }
  else
    return BIG_NAN;
}

.log1p_ser_mercator(x, prec) ⇒ Complex

Computes natural logarithm of x 1+ by mercator series expansion.

Examples:

BigMathR::Log.log1p_ser_mercator(1, 20)
#=> 0.69314718055994530942e0

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'ext/bigdecimal/math_r/log.c', line 25

static VALUE
__impl_log1p_ser_mercator(VALUE uunused_obj, VALUE x, VALUE prec)
{
  const ID cover_p = rb_intern("cover?");
  VALUE domain = rb_range_new(INT2FIX(-1), INT2FIX(1), false);
  if (RTEST(rb_funcall(domain, cover_p, 1, x)))
  {
    if (rb_num_equal_p(x, INT2FIX(-1)))
      return BIG_MINUS_INF;
    else if (rb_num_equal_p(x, INT2FIX(1)))
      return rb_bigmath_const_log2(prec);
    else
      return log1p_ser_mercator(x, prec);
  }
  else
    return BIG_NAN;
}

.log2_edf(x, prec) ⇒ BigDecimal

Computes binary logarithm of x.
In terms of solving real number solutions, the implementation is the same as log2() in C.

Examples:

BigMathR::EDF.log2(2, 20) #=> 0.1e1

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number



144
145
146
147
148
# File 'ext/bigdecimal/math_r/log.c', line 144

static VALUE
__impl_log2_edf(VALUE unused_obj, VALUE x, VALUE prec)
{
  return log2_branch(x, prec, log2_edf);
}

.log_edf(x, prec) ⇒ BigDecimal

Computes natural logarithm of x.
In terms of solving real number solutions, the implementation is the same as log() in C.

Examples:

BigMathR::EDF.log(2, 20) #=> 0.69314718055994530942e0

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number



125
126
127
128
129
# File 'ext/bigdecimal/math_r/log.c', line 125

static VALUE
__impl_log_edf(VALUE unused_obj, VALUE x, VALUE prec)
{
  return log_branch(x, prec, log_edf);
}

.log_ser_okumura(x, prec) ⇒ BigDecimal

Computes natural logarithm of x by series expansion.

Examples:

BigMathR::Log.log_ser_okumura(2, 20)
#=> 0.69314718055994530942e0

Parameters:

  • x (Numeric)

    Numerical argument

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

Raises:

  • (TypeError)

    prec is not an Integer

  • (RangeError)

    prec is zero or negative number

Since:

  • 0.1.0



106
107
108
109
110
# File 'ext/bigdecimal/math_r/log.c', line 106

static VALUE
__impl_log_ser_okumura(VALUE uunused_obj, VALUE x, VALUE prec)
{
  return log_branch(x, prec, log_ser_okumura);
}