mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
INFINITY is float. That of double is HUGE_VAL.
It seems HUGE_VAL is already used. Why not eliminate INTINITY. NAN is also float. That of double is called nan(). This is also fixed. Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
09b4d6e8cd
commit
3ca0948f68
11 changed files with 57 additions and 30 deletions
2
array.c
2
array.c
|
@ -5012,7 +5012,7 @@ rb_ary_cycle_size(VALUE self, VALUE args, VALUE eobj)
|
|||
n = RARRAY_AREF(args, 0);
|
||||
}
|
||||
if (RARRAY_LEN(self) == 0) return INT2FIX(0);
|
||||
if (n == Qnil) return DBL2NUM(INFINITY);
|
||||
if (n == Qnil) return DBL2NUM(HUGE_VAL);
|
||||
mul = NUM2LONG(n);
|
||||
if (mul <= 0) return INT2FIX(0);
|
||||
n = LONG2FIX(mul);
|
||||
|
|
2
bignum.c
2
bignum.c
|
@ -6130,7 +6130,7 @@ big_fdiv(VALUE x, VALUE y, long ey)
|
|||
#if SIZEOF_LONG > SIZEOF_INT
|
||||
{
|
||||
/* Visual C++ can't be here */
|
||||
if (l > INT_MAX) return INFINITY;
|
||||
if (l > INT_MAX) return HUGE_VAL;
|
||||
if (l < INT_MIN) return 0.0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -805,7 +805,7 @@ AS_IF([test "$GCC:${warnflags+set}:no" = yes::no], [
|
|||
])
|
||||
RUBY_TRY_CFLAGS(-Qunused-arguments, [RUBY_APPEND_OPTIONS(rb_cv_wsuppress_flags, -Qunused-arguments)])
|
||||
|
||||
for n in infinity nan; do
|
||||
for n in huge_val infinity nan; do
|
||||
m=AS_TR_CPP($n)
|
||||
AC_CACHE_CHECK([whether $m is available without C99 option], rb_cv_$n,
|
||||
[AC_COMPILE_IFELSE(
|
||||
|
@ -2393,6 +2393,7 @@ AC_CHECK_FUNCS(memmem)
|
|||
AC_CHECK_FUNCS(mkfifo)
|
||||
AC_CHECK_FUNCS(mknod)
|
||||
AC_CHECK_FUNCS(mktime)
|
||||
AC_CHECK_FUNCS(nanf) # We need nan(), but HAVE_NAN conflicts...
|
||||
AC_CHECK_FUNCS(openat)
|
||||
AC_CHECK_FUNCS(pipe2)
|
||||
AC_CHECK_FUNCS(poll)
|
||||
|
|
2
enum.c
2
enum.c
|
@ -2887,7 +2887,7 @@ enum_cycle_size(VALUE self, VALUE args, VALUE eobj)
|
|||
size = enum_size(self, args, 0);
|
||||
if (NIL_P(size) || FIXNUM_ZERO_P(size)) return size;
|
||||
|
||||
if (NIL_P(n)) return DBL2NUM(INFINITY);
|
||||
if (NIL_P(n)) return DBL2NUM(HUGE_VAL);
|
||||
if (mul <= 0) return INT2FIX(0);
|
||||
n = LONG2FIX(mul);
|
||||
return rb_funcallv(size, '*', 1, &n);
|
||||
|
|
|
@ -397,7 +397,7 @@ enumerator_initialize(int argc, VALUE *argv, VALUE obj)
|
|||
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
|
||||
if (argc) {
|
||||
if (NIL_P(argv[0]) || rb_respond_to(argv[0], id_call) ||
|
||||
(RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
|
||||
(RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == HUGE_VAL)) {
|
||||
size = argv[0];
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -155,6 +155,10 @@ RUBY_EXTERN const union bytesequence4_or_float rb_nan;
|
|||
# define NAN (rb_nan.float_value)
|
||||
#endif
|
||||
|
||||
#ifndef HUGE_VAL
|
||||
# define HUGE_VAL ((double)INFINITY)
|
||||
#endif
|
||||
|
||||
#ifndef isinf
|
||||
# ifndef HAVE_ISINF
|
||||
# if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
|
||||
|
|
11
marshal.c
11
marshal.c
|
@ -1678,13 +1678,18 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
const char *ptr = RSTRING_PTR(str);
|
||||
|
||||
if (strcmp(ptr, "nan") == 0) {
|
||||
d = NAN;
|
||||
d =
|
||||
#ifdef HAVE_NANF
|
||||
nan("");
|
||||
#else
|
||||
(double)NAN;
|
||||
#endif
|
||||
}
|
||||
else if (strcmp(ptr, "inf") == 0) {
|
||||
d = INFINITY;
|
||||
d = HUGE_VAL;
|
||||
}
|
||||
else if (strcmp(ptr, "-inf") == 0) {
|
||||
d = -INFINITY;
|
||||
d = -HUGE_VAL;
|
||||
}
|
||||
else {
|
||||
char *e;
|
||||
|
|
18
math.c
18
math.c
|
@ -382,8 +382,8 @@ math_atanh(VALUE unused_obj, VALUE x)
|
|||
/* check for domain error */
|
||||
if (d < -1.0 || +1.0 < d) domain_error("atanh");
|
||||
/* check for pole error */
|
||||
if (d == -1.0) return DBL2NUM(-INFINITY);
|
||||
if (d == +1.0) return DBL2NUM(+INFINITY);
|
||||
if (d == -1.0) return DBL2NUM(-HUGE_VAL);
|
||||
if (d == +1.0) return DBL2NUM(+HUGE_VAL);
|
||||
return DBL2NUM(atanh(d));
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ math_log1(VALUE x)
|
|||
/* check for domain error */
|
||||
if (d < 0.0) domain_error("log");
|
||||
/* check for pole error */
|
||||
if (d == 0.0) return -INFINITY;
|
||||
if (d == 0.0) return -HUGE_VAL;
|
||||
|
||||
return log(d) + numbits * M_LN2; /* log(d * 2 ** numbits) */
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ math_log2(VALUE unused_obj, VALUE x)
|
|||
/* check for domain error */
|
||||
if (d < 0.0) domain_error("log2");
|
||||
/* check for pole error */
|
||||
if (d == 0.0) return DBL2NUM(-INFINITY);
|
||||
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
|
||||
|
||||
return DBL2NUM(log2(d) + numbits); /* log2(d * 2 ** numbits) */
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ math_log10(VALUE unused_obj, VALUE x)
|
|||
/* check for domain error */
|
||||
if (d < 0.0) domain_error("log10");
|
||||
/* check for pole error */
|
||||
if (d == 0.0) return DBL2NUM(-INFINITY);
|
||||
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
|
||||
|
||||
return DBL2NUM(log10(d) + numbits * log10(2)); /* log10(d * 2 ** numbits) */
|
||||
}
|
||||
|
@ -855,10 +855,10 @@ math_gamma(VALUE unused_obj, VALUE x)
|
|||
/* check for domain error */
|
||||
if (isinf(d)) {
|
||||
if (signbit(d)) domain_error("gamma");
|
||||
return DBL2NUM(INFINITY);
|
||||
return DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
if (d == 0.0) {
|
||||
return signbit(d) ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
|
||||
return signbit(d) ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
if (d == floor(d)) {
|
||||
if (d < 0.0) domain_error("gamma");
|
||||
|
@ -893,11 +893,11 @@ math_lgamma(VALUE unused_obj, VALUE x)
|
|||
/* check for domain error */
|
||||
if (isinf(d)) {
|
||||
if (signbit(d)) domain_error("lgamma");
|
||||
return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1));
|
||||
return rb_assoc_new(DBL2NUM(HUGE_VAL), INT2FIX(1));
|
||||
}
|
||||
if (d == 0.0) {
|
||||
VALUE vsign = signbit(d) ? INT2FIX(-1) : INT2FIX(+1);
|
||||
return rb_assoc_new(DBL2NUM(INFINITY), vsign);
|
||||
return rb_assoc_new(DBL2NUM(HUGE_VAL), vsign);
|
||||
}
|
||||
v = DBL2NUM(lgamma_r(d, &sign));
|
||||
return rb_assoc_new(v, INT2FIX(sign));
|
||||
|
|
34
numeric.c
34
numeric.c
|
@ -1795,7 +1795,7 @@ flo_next_float(VALUE vx)
|
|||
{
|
||||
double x, y;
|
||||
x = NUM2DBL(vx);
|
||||
y = nextafter(x, INFINITY);
|
||||
y = nextafter(x, HUGE_VAL);
|
||||
return DBL2NUM(y);
|
||||
}
|
||||
|
||||
|
@ -1846,7 +1846,7 @@ flo_prev_float(VALUE vx)
|
|||
{
|
||||
double x, y;
|
||||
x = NUM2DBL(vx);
|
||||
y = nextafter(x, -INFINITY);
|
||||
y = nextafter(x, -HUGE_VAL);
|
||||
return DBL2NUM(y);
|
||||
}
|
||||
|
||||
|
@ -2451,7 +2451,7 @@ ruby_float_step_size(double beg, double end, double unit, int excl)
|
|||
return unit > 0 ? beg <= end : beg >= end;
|
||||
}
|
||||
if (unit == 0) {
|
||||
return INFINITY;
|
||||
return HUGE_VAL;
|
||||
}
|
||||
if (err>0.5) err=0.5;
|
||||
if (excl) {
|
||||
|
@ -2507,7 +2507,7 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
|
|||
|
||||
diff = FIX2LONG(step);
|
||||
if (diff == 0) {
|
||||
return DBL2NUM(INFINITY);
|
||||
return DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
delta = FIX2LONG(to) - FIX2LONG(from);
|
||||
if (diff < 0) {
|
||||
|
@ -2533,7 +2533,7 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
|
|||
VALUE result;
|
||||
ID cmp = '>';
|
||||
switch (rb_cmpint(rb_num_coerce_cmp(step, INT2FIX(0), id_cmp), step, INT2FIX(0))) {
|
||||
case 0: return DBL2NUM(INFINITY);
|
||||
case 0: return DBL2NUM(HUGE_VAL);
|
||||
case -1: cmp = '<'; break;
|
||||
}
|
||||
if (RTEST(rb_funcall(from, cmp, 1, to))) return INT2FIX(0);
|
||||
|
@ -2604,7 +2604,7 @@ num_step_scan_args(int argc, const VALUE *argv, VALUE *to, VALUE *step)
|
|||
}
|
||||
desc = num_step_negative_p(*step);
|
||||
if (NIL_P(*to)) {
|
||||
*to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
|
||||
*to = desc ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
@ -3650,7 +3650,13 @@ rb_int_fdiv_double(VALUE x, VALUE y)
|
|||
else if (RB_TYPE_P(x, T_BIGNUM)) {
|
||||
return rb_big_fdiv_double(x, y);
|
||||
}
|
||||
return NAN;
|
||||
else {
|
||||
#ifdef HAVE_NANF
|
||||
return nan("");
|
||||
#else
|
||||
return (double)NAN;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3967,7 +3973,7 @@ fix_pow(VALUE x, VALUE y)
|
|||
if (b == 1) return x;
|
||||
if (a == 0) {
|
||||
if (b > 0) return INT2FIX(0);
|
||||
return DBL2NUM(INFINITY);
|
||||
return DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
return int_pow(a, b);
|
||||
}
|
||||
|
@ -3987,7 +3993,7 @@ fix_pow(VALUE x, VALUE y)
|
|||
double dy = RFLOAT_VALUE(y);
|
||||
if (dy == 0.0) return DBL2NUM(1.0);
|
||||
if (a == 0) {
|
||||
return DBL2NUM(dy < 0 ? INFINITY : 0.0);
|
||||
return DBL2NUM(dy < 0 ? HUGE_VAL : 0.0);
|
||||
}
|
||||
if (a == 1) return DBL2NUM(1.0);
|
||||
{
|
||||
|
@ -5555,11 +5561,17 @@ Init_Numeric(void)
|
|||
/*
|
||||
* An expression representing positive infinity.
|
||||
*/
|
||||
rb_define_const(rb_cFloat, "INFINITY", DBL2NUM(INFINITY));
|
||||
rb_define_const(rb_cFloat, "INFINITY", DBL2NUM(HUGE_VAL));
|
||||
/*
|
||||
* An expression representing a value which is "not a number".
|
||||
*/
|
||||
rb_define_const(rb_cFloat, "NAN", DBL2NUM(NAN));
|
||||
rb_define_const(rb_cFloat, "NAN",
|
||||
#ifdef HAVE_NANF
|
||||
DBL2NUM(nan(""))
|
||||
#else
|
||||
DBL2NUM((double)NAN)
|
||||
#endif
|
||||
);
|
||||
|
||||
rb_define_method(rb_cFloat, "to_s", flo_to_s, 0);
|
||||
rb_define_alias(rb_cFloat, "inspect", "to_s");
|
||||
|
|
|
@ -1072,7 +1072,12 @@ nurat_expt(VALUE self, VALUE other)
|
|||
den = ONE;
|
||||
}
|
||||
if (RB_FLOAT_TYPE_P(num)) { /* infinity due to overflow */
|
||||
if (RB_FLOAT_TYPE_P(den)) return DBL2NUM(NAN);
|
||||
if (RB_FLOAT_TYPE_P(den))
|
||||
#ifdef HAVE_NANF
|
||||
return DBL2NUM(nan(""));
|
||||
#else
|
||||
return DBL2NUM((double)NAN);
|
||||
#endif
|
||||
return num;
|
||||
}
|
||||
if (RB_FLOAT_TYPE_P(den)) { /* infinity due to overflow */
|
||||
|
|
|
@ -1060,7 +1060,7 @@ loop_stop(VALUE dummy, VALUE exc)
|
|||
static VALUE
|
||||
rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
|
||||
{
|
||||
return DBL2NUM(INFINITY);
|
||||
return DBL2NUM(HUGE_VAL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue