Module: BigMathR::EDF

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

Overview

A module that treats the exponential decomposition formula. It is used internally.
This formula was discovered by the author shortly afterwards. It will be proven in time.

Reference

Exponential Decomposition Formula

Class Method Summary collapse

Class Method Details

.expxt(x, t, prec) ⇒ BigDecimal

Calculate the exponential function of x with base t.

Examples:

BigMathR::EDF.expxt(0.5, BigMathR.LOG2(20), 20)
#=> 0.14142135623730950488e1

Parameters:

  • x (Numeric)

    Numerical Argument. Domain as 0<=x<1.

  • t (Numeric)

    Base of x. 1 = e, log2 = 2

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Fraction number

Since:

  • 0.1.0



55
56
57
58
59
# File 'ext/bigdecimal/math_r/edf.c', line 55

static VALUE
__impl_edf_expxt(VALUE unused_obj, VALUE x, VALUE t, VALUE prec)
{
	return rb_bigmath_expxt(x, t, prec);
}

.logxt(x, t, prec) ⇒ BigDecimal

Computes fraction of x with its complement t in the exponential decomposition.
Complement is equal to the base x, and the decomposition varies depending on the value given.

Examples:

BigMathR::EDF.logxt(2, 10, 20) #=> 0.30102999566398119521e0
BigMathR::EDF.logxt(2, 2, 20) #=> 0.1e1
BigMathR::EDF.logxt(2, Math::E, Float::DIG) #=> 0.693147180559945e0

Parameters:

  • x (Numeric)

    Numerical Argument. Domain as 1<=x<=t.

  • t (Numeric)

    Complement of x. e = ln(x), 2 = log_2(x), 10 = log_10(x)

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Solution of log_t(x)

Raises:

  • (FloatDomainError)

    Numerical arguments are out of range

See Also:

  • in Oberon - Niklaus Wirth

Since:

  • 0.1.0



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'ext/bigdecimal/math_r/edf.c', line 137

static VALUE
__impl_edf_logxt(VALUE unused_obj, VALUE x, VALUE t, VALUE prec)
{
	rb_check_precise(prec);
	x = rb_num_canonicalize(x, prec, ARG_REAL, ARG_RAWVALUE);
	if (rb_num_notequal_p(x, x) ||
	    rb_num_negative_p(x) || 
	    NUM2INT(rb_num_cmpeql(INT2FIX(1), x)) == 1 || 
	    NUM2INT(rb_num_cmpeql(x, t)) != -1)
	{
		if (rb_num_equal_p(x, t))
			return BIG_ONE;
		rb_raise(rb_eFloatDomainError, "Numerical arguments are out of range: (1 <= x <= t)");
	}
	t = rb_num_canonicalize(t, prec, ARG_REAL, ARG_RAWVALUE);
	x = logxt_edf(x, t, prec);
	return rb_num_round(x, prec);
}

.rcm10(x) ⇒ Array

Based on the radix complementation method, exponentially-decompose x on radix 10.
It behaves the same as frexp() in C, except that the radix is 10 and the value range is 1 leq y lt 10.
If x is not positive finite except 0, then it is inherently undefined. However, if x is negative finite, it will return a value range of -10 lt y leq -1.

Examples:

fra, exp = BigMathR::EDF.rcm10(3)
#=> [(3/1), 0]
fra = BigMathR::EDF.logxt(fra, 10, 20)
#=> 0.4771212547196624373e0
log10_3 = exp + fra
#=> 0.4771212547196624373e0
Math.log10(3) == log10_3.to_f
#=> true

Parameters:

  • x (Numeric)

    Numerical argument

Returns:

  • (Array)

    Decomposed values as [fraction, exponent]

Since:

  • 0.1.0



112
113
114
115
116
117
118
# File 'ext/bigdecimal/math_r/edf.c', line 112

static VALUE
__impl_edf_rcm10(VALUE unused_obj, VALUE x)
{
	VALUE exp, fra;
	fra = rcm10_edf(x, &exp);
	return rb_assoc_new(fra, exp);
}

.rcm2(x) ⇒ Array

Based on the radix complementation method, exponentially-decompose x on radix 2.
It behaves the same as frexp() in C, except that the value range is 1 leq y lt 2 with its exponent.
If x is not positive finite except 0, then it is inherently undefined. However, if x is negative finite, it will return a value range of -2 lt y leq -1.

Examples:

fra, exp = BigMathR::EDF.rcm2(3)
#=> [(3/2), 1]
fra = BigMathR::EDF.logxt(fra, 2, 20)
#=> 0.58496250072115618145e0
log2_3 = exp + fra
#=> 0.158496250072115618145e1
Math.log2(3) == log2_3.to_f
#=> true

Parameters:

  • x (Numeric)

    Numerical argument

Returns:

  • (Array)

    Decomposed values as [fraction, exponent]

Since:

  • 0.1.0



82
83
84
85
86
87
88
# File 'ext/bigdecimal/math_r/edf.c', line 82

static VALUE
__impl_edf_rcm2(VALUE unused_obj, VALUE x)
{
	VALUE exp, fra;
	fra = rcm2_edf(x, &exp);
	return rb_assoc_new(fra, exp);
}