mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
math.c: get_double_rshift
* math.c (get_double_rshift): extract bignum to double conversion with bit offset. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7c0cb4351a
commit
92b98a982b
1 changed files with 12 additions and 25 deletions
37
math.c
37
math.c
|
@ -456,9 +456,8 @@ math_log(int argc, const VALUE *argv, VALUE obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static double
|
static double
|
||||||
math_log1(VALUE x)
|
get_double_rshift(VALUE x, size_t *pnumbits)
|
||||||
{
|
{
|
||||||
double d;
|
|
||||||
size_t numbits;
|
size_t numbits;
|
||||||
|
|
||||||
if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
|
if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
|
||||||
|
@ -469,8 +468,16 @@ math_log1(VALUE x)
|
||||||
else {
|
else {
|
||||||
numbits = 0;
|
numbits = 0;
|
||||||
}
|
}
|
||||||
|
*pnumbits = numbits;
|
||||||
|
return Get_Double(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
math_log1(VALUE x)
|
||||||
|
{
|
||||||
|
size_t numbits;
|
||||||
|
double d = get_double_rshift(x, &numbits);
|
||||||
|
|
||||||
d = Get_Double(x);
|
|
||||||
/* check for domain error */
|
/* check for domain error */
|
||||||
if (d < 0.0) domain_error("log");
|
if (d < 0.0) domain_error("log");
|
||||||
/* check for pole error */
|
/* check for pole error */
|
||||||
|
@ -511,19 +518,9 @@ extern double log2(double);
|
||||||
static VALUE
|
static VALUE
|
||||||
math_log2(VALUE obj, VALUE x)
|
math_log2(VALUE obj, VALUE x)
|
||||||
{
|
{
|
||||||
double d;
|
|
||||||
size_t numbits;
|
size_t numbits;
|
||||||
|
double d = get_double_rshift(x, &numbits);
|
||||||
|
|
||||||
if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
|
|
||||||
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
|
|
||||||
numbits -= DBL_MANT_DIG;
|
|
||||||
x = rb_big_rshift(x, SIZET2NUM(numbits));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numbits = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
d = Get_Double(x);
|
|
||||||
/* check for domain error */
|
/* check for domain error */
|
||||||
if (d < 0.0) domain_error("log2");
|
if (d < 0.0) domain_error("log2");
|
||||||
/* check for pole error */
|
/* check for pole error */
|
||||||
|
@ -551,19 +548,9 @@ math_log2(VALUE obj, VALUE x)
|
||||||
static VALUE
|
static VALUE
|
||||||
math_log10(VALUE obj, VALUE x)
|
math_log10(VALUE obj, VALUE x)
|
||||||
{
|
{
|
||||||
double d;
|
|
||||||
size_t numbits;
|
size_t numbits;
|
||||||
|
double d = get_double_rshift(x, &numbits);
|
||||||
|
|
||||||
if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
|
|
||||||
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
|
|
||||||
numbits -= DBL_MANT_DIG;
|
|
||||||
x = rb_big_rshift(x, SIZET2NUM(numbits));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
numbits = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
d = Get_Double(x);
|
|
||||||
/* check for domain error */
|
/* check for domain error */
|
||||||
if (d < 0.0) domain_error("log10");
|
if (d < 0.0) domain_error("log10");
|
||||||
/* check for pole error */
|
/* check for pole error */
|
||||||
|
|
Loading…
Reference in a new issue