mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* math.c (domain_check): a new function to check domain error
explicitly for systems that return NaN like FreeBSD. [ruby-core:07019] * math.c (math_acos, math_asin, math_acosh, math_atanh, math_log, math_log10, math_sqrt): use domain_check(). * math.c (math_sqrt): fix documentation flaw. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b5e187c5f7
commit
bb6a09ebe2
2 changed files with 40 additions and 24 deletions
11
ChangeLog
11
ChangeLog
|
@ -2,6 +2,17 @@ Thu Jul 27 22:21:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* time.c (time_to_s): fixed format mismatch.
|
* time.c (time_to_s): fixed format mismatch.
|
||||||
|
|
||||||
|
Thu Jul 27 21:19:54 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* math.c (domain_check): a new function to check domain error
|
||||||
|
explicitly for systems that return NaN like FreeBSD.
|
||||||
|
[ruby-core:07019]
|
||||||
|
|
||||||
|
* math.c (math_acos, math_asin, math_acosh, math_atanh, math_log,
|
||||||
|
math_log10, math_sqrt): use domain_check().
|
||||||
|
|
||||||
|
* math.c (math_sqrt): fix documentation flaw.
|
||||||
|
|
||||||
Thu Jul 27 18:12:12 2006 WATANABE Hirofumi <eban@ruby-lang.org>
|
Thu Jul 27 18:12:12 2006 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* time.c: need to declare time_utc_offset.
|
* time.c: need to declare time_utc_offset.
|
||||||
|
|
53
math.c
53
math.c
|
@ -22,6 +22,27 @@ VALUE rb_mMath;
|
||||||
Need_Float(y);\
|
Need_Float(y);\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
static void
|
||||||
|
domain_check(x, msg)
|
||||||
|
double x;
|
||||||
|
char *msg;
|
||||||
|
{
|
||||||
|
while(1) {
|
||||||
|
if (errno) {
|
||||||
|
rb_sys_fail(msg);
|
||||||
|
}
|
||||||
|
if (isnan(x)) {
|
||||||
|
#if defined(EDOM)
|
||||||
|
errno = EDOM;
|
||||||
|
#elif define(ERANGE)
|
||||||
|
errno = ERANGE;
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
|
@ -41,7 +62,6 @@ math_atan2(obj, y, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Math.cos(x) => float
|
* Math.cos(x) => float
|
||||||
|
@ -108,9 +128,7 @@ math_acos(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = acos(RFLOAT(x)->value);
|
d = acos(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "acos");
|
||||||
rb_sys_fail("acos");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +148,7 @@ math_asin(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = asin(RFLOAT(x)->value);
|
d = asin(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "asin");
|
||||||
rb_sys_fail("asin");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,9 +258,7 @@ math_acosh(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = acosh(RFLOAT(x)->value);
|
d = acosh(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "acosh");
|
||||||
rb_sys_fail("acosh");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,9 +293,7 @@ math_atanh(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = atanh(RFLOAT(x)->value);
|
d = atanh(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "atanh");
|
||||||
rb_sys_fail("atanh");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,9 +337,7 @@ math_log(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = log(RFLOAT(x)->value);
|
d = log(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "log");
|
||||||
rb_sys_fail("log");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,9 +357,7 @@ math_log10(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = log10(RFLOAT(x)->value);
|
d = log10(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "log10");
|
||||||
rb_sys_fail("log10");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,8 +365,7 @@ math_log10(obj, x)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Math.sqrt(numeric) => float
|
* Math.sqrt(numeric) => float
|
||||||
*
|
*
|
||||||
* Returns the non-negative square root of <i>numeric</i>. Raises
|
* Returns the non-negative square root of <i>numeric</i>.
|
||||||
* <code>ArgError</code> if <i>numeric</i> is less than zero.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -370,9 +377,7 @@ math_sqrt(obj, x)
|
||||||
Need_Float(x);
|
Need_Float(x);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d = sqrt(RFLOAT(x)->value);
|
d = sqrt(RFLOAT(x)->value);
|
||||||
if (errno) {
|
domain_check(d, "sqrt");
|
||||||
rb_sys_fail("sqrt");
|
|
||||||
}
|
|
||||||
return rb_float_new(d);
|
return rb_float_new(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue