Project

General

Profile

Feature #15435 » use-predefined-infinity.patch

shuujii (Shuji KOBAYASHI), 12/19/2018 08:49 AM

View differences:

array.c
n = RARRAY_AREF(args, 0);
}
if (RARRAY_LEN(self) == 0) return INT2FIX(0);
if (n == Qnil) return DBL2NUM(HUGE_VAL);
if (n == Qnil) return rb_float_positive_infinity;
mul = NUM2LONG(n);
if (mul <= 0) return INT2FIX(0);
n = LONG2FIX(mul);
enum.c
size = enum_size(self, args, 0);
if (NIL_P(size) || FIXNUM_ZERO_P(size)) return size;
if (NIL_P(n)) return DBL2NUM(HUGE_VAL);
if (NIL_P(n)) return rb_float_positive_infinity;
if (mul <= 0) return INT2FIX(0);
n = LONG2FIX(mul);
return rb_funcallv(size, '*', 1, &n);
enumerator.c
}
if (NIL_P(e)) {
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
if (!rb_obj_is_kind_of(s, rb_cNumeric)) {
......
}
if (rb_equal(s, INT2FIX(0))) {
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
len_1 = rb_int_idiv(rb_int_minus(e, b), s);
include/ruby/ruby.h
RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
RUBY_EXTERN VALUE rb_float_negative_infinity, rb_float_positive_infinity;
static inline VALUE
rb_class_of(VALUE obj)
{
internal.h
}
/* out of range */
#endif
if (isinf(d)) {
return d < 0 ? rb_float_negative_infinity : rb_float_positive_infinity;
}
return rb_float_new_in_heap(d);
}
math.c
/* check for domain error */
if (d < -1.0 || +1.0 < d) domain_error("atanh");
/* check for pole error */
if (d == -1.0) return DBL2NUM(-HUGE_VAL);
if (d == +1.0) return DBL2NUM(+HUGE_VAL);
if (d == -1.0) return rb_float_negative_infinity;
if (d == +1.0) return rb_float_positive_infinity;
return DBL2NUM(atanh(d));
}
......
/* check for domain error */
if (d < 0.0) domain_error("log2");
/* check for pole error */
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
if (d == 0.0) return rb_float_negative_infinity;
return DBL2NUM(log2(d) + numbits); /* log2(d * 2 ** numbits) */
}
......
/* check for domain error */
if (d < 0.0) domain_error("log10");
/* check for pole error */
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
if (d == 0.0) return rb_float_negative_infinity;
return DBL2NUM(log10(d) + numbits * log10(2)); /* log10(d * 2 ** numbits) */
}
......
/* check for domain error */
if (isinf(d)) {
if (signbit(d)) domain_error("gamma");
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
if (d == 0.0) {
return signbit(d) ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
return signbit(d) ? rb_float_negative_infinity : rb_float_positive_infinity;
}
if (d == floor(d)) {
if (d < 0.0) domain_error("gamma");
......
/* check for domain error */
if (isinf(d)) {
if (signbit(d)) domain_error("lgamma");
return rb_assoc_new(DBL2NUM(HUGE_VAL), INT2FIX(1));
return rb_assoc_new(rb_float_positive_infinity, INT2FIX(1));
}
if (d == 0.0) {
VALUE vsign = signbit(d) ? INT2FIX(-1) : INT2FIX(+1);
return rb_assoc_new(DBL2NUM(HUGE_VAL), vsign);
return rb_assoc_new(rb_float_positive_infinity, vsign);
}
v = DBL2NUM(lgamma_r(d, &sign));
return rb_assoc_new(v, INT2FIX(sign));
numeric.c
VALUE rb_eZeroDivError;
VALUE rb_eFloatDomainError;
VALUE rb_float_negative_infinity, rb_float_positive_infinity;
static ID id_to, id_by;
void
......
diff = FIX2LONG(step);
if (diff == 0) {
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
delta = FIX2LONG(to) - FIX2LONG(from);
if (diff < 0) {
......
VALUE result;
ID cmp = '>';
switch (rb_cmpint(rb_num_coerce_cmp(step, INT2FIX(0), id_cmp), step, INT2FIX(0))) {
case 0: return DBL2NUM(HUGE_VAL);
case 0: return rb_float_positive_infinity;
case -1: cmp = '<'; break;
}
if (RTEST(rb_funcall(from, cmp, 1, to))) return INT2FIX(0);
......
}
desc = num_step_negative_p(*step);
if (fix_nil && NIL_P(*to)) {
*to = desc ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
*to = desc ? rb_float_negative_infinity : rb_float_positive_infinity;
}
return desc;
}
......
if (b == 1) return x;
if (a == 0) {
if (b > 0) return INT2FIX(0);
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
return int_pow(a, b);
}
......
double dy = RFLOAT_VALUE(y);
if (dy == 0.0) return DBL2NUM(1.0);
if (a == 0) {
return DBL2NUM(dy < 0 ? HUGE_VAL : 0.0);
return dy < 0 ? rb_float_positive_infinity : DBL2NUM(0.0);
}
if (a == 1) return DBL2NUM(1.0);
{
......
/*
* An expression representing positive infinity.
*/
rb_define_const(rb_cFloat, "INFINITY", DBL2NUM(HUGE_VAL));
rb_define_const(rb_cFloat, "INFINITY",
rb_float_positive_infinity = rb_float_new_in_heap(HUGE_VAL));
/*
* An expression representing a value which is "not a number".
*/
......
id_to = rb_intern("to");
id_by = rb_intern("by");
rb_global_variable(&rb_float_negative_infinity);
rb_float_negative_infinity = rb_float_new_in_heap(-HUGE_VAL);
}
#undef rb_float_value
parse.y
RCOMPLEX_SET_IMAG(lit, negate_lit(p, RCOMPLEX(lit)->imag));
break;
case T_FLOAT:
RFLOAT(lit)->float_value = -RFLOAT_VALUE(lit);
if (lit == rb_float_positive_infinity) {
lit = rb_float_negative_infinity;
}
else {
RFLOAT(lit)->float_value = -RFLOAT_VALUE(lit);
}
break;
unknown:
default:
range.c
return ruby_num_interval_step_size(b, e, INT2FIX(1), EXCL(range));
}
if (NIL_P(e)) {
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
}
rational.c
VALUE mul;
if (!FIXNUM_P(nexp)) {
overflow:
return sign == '-' ? DBL2NUM(-HUGE_VAL) : DBL2NUM(HUGE_VAL);
return sign == '-' ? rb_float_negative_infinity : rb_float_positive_infinity;
}
mul = f_expt10(LONG2NUM(-FIX2LONG(nexp)));
if (RB_FLOAT_TYPE_P(mul)) goto overflow;
test/ruby/test_float.rb
end
end;
end
def test_predefined_infinity
assert_same(-Float::INFINITY, -1e1020)
assert_same(-Float::INFINITY, -1*Float::INFINITY)
assert_same(-Float::INFINITY, 1/-0.0)
assert_same(Float::INFINITY, 1e1020)
assert_same(Float::INFINITY, Float::INFINITY+1)
assert_same(Float::INFINITY, 1/0.0)
end
end
vm_eval.c
static VALUE
rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
{
return DBL2NUM(HUGE_VAL);
return rb_float_positive_infinity;
}
/*
(1-1/3)