149
# Computes the value of e (the base of natural logarithms) raised to the
150
# power of x, to the specified number of digits of precision.
152
# If x is infinite or NaN, returns NaN.
154
# BigMath::exp(BigDecimal.new('1'), 10).to_s
155
# -> "0.271828182845904523536028752390026306410273E1"
157
raise ArgumentError, "Zero or negative precision for exp" if prec <= 0
158
return BigDecimal("NaN") if x.infinite? || x.nan?
159
n = prec + BigDecimal.double_fig
160
one = BigDecimal("1")
161
x = -x if neg = x < 0
167
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
168
m = BigDecimal.double_fig if m < BigDecimal.double_fig
178
y.round(prec - y.exponent)
182
# Computes the natural logarithm of x to the specified number of digits
185
# Returns x if x is infinite or NaN.
188
raise ArgumentError, "Zero or negative argument for log" if x <= 0 || prec <= 0
189
return x if x.infinite? || x.nan?
190
one = BigDecimal("1")
191
two = BigDecimal("2")
192
n = prec + BigDecimal.double_fig
193
if (expo = x.exponent) < 0 || expo >= 3
194
x = x.mult(BigDecimal("1E#{-expo}"), n)
198
x = (x - one).div(x + one,n)
203
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
204
m = BigDecimal.double_fig if m < BigDecimal.double_fig
212
y += log(BigDecimal("10"),prec) * BigDecimal(expo.to_s)
217
148
# Computes the value of pi to the specified number of digits of precision.
219
150
raise ArgumentError, "Zero or negative argument for PI" if prec <= 0