Project

General

Profile

Feature #5321 ยป numeric-exact-5321.patch

jeremyevans0 (Jeremy Evans), 08/01/2019 12:57 AM

View differences:

complex.c
static ID id_abs, id_arg,
id_denominator, id_fdiv, id_numerator, id_quo,
id_real_p, id_i_real, id_i_imag,
id_real_p, id_i_real, id_i_imag, id_exact_p,
id_finite_p, id_infinite_p, id_rationalize,
id_PI;
#define id_to_i idTo_i
......
#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
/*
* call-seq:
* cmp.exact? -> true or false
*
* Returns +true+ if +cmp+'s real and imaginary parts are both exact numbers,
* otherwise returns +false+.
*/
static VALUE
rb_complex_exact_p(VALUE self)
{
get_dat1(self);
if (RTEST(rb_funcall(dat->real, id_exact_p, 0)) &&
RTEST(rb_funcall(dat->imag, id_exact_p, 0))) {
return Qtrue;
}
return Qfalse;
}
/*
* call-seq:
* cmp.finite? -> true or false
......
id_real_p = rb_intern("real?");
id_i_real = rb_intern("@real");
id_i_imag = rb_intern("@image"); /* @image, not @imag */
id_exact_p = rb_intern("exact?");
id_finite_p = rb_intern("finite?");
id_infinite_p = rb_intern("infinite?");
id_rationalize = rb_intern("rationalize");
......
rb_undef_method(rb_cComplex, "positive?");
rb_undef_method(rb_cComplex, "negative?");
rb_define_method(rb_cComplex, "exact?", rb_complex_exact_p, 0);
rb_define_method(rb_cComplex, "finite?", rb_complex_finite_p, 0);
rb_define_method(rb_cComplex, "infinite?", rb_complex_infinite_p, 0);
ext/bigdecimal/bigdecimal.c
return Qfalse;
}
/* Returns false as BigDecimal is not exact. */
static VALUE
BigDecimal_IsExact(VALUE self)
{
return Qfalse;
}
/* Returns nil, -1, or +1 depending on whether the value is finite,
* -Infinity, or +Infinity.
*/
......
rb_define_method(rb_cBigDecimal, "exponent", BigDecimal_exponent, 0);
rb_define_method(rb_cBigDecimal, "sign", BigDecimal_sign, 0);
rb_define_method(rb_cBigDecimal, "nan?", BigDecimal_IsNaN, 0);
rb_define_method(rb_cBigDecimal, "exact?", BigDecimal_IsExact, 0);
rb_define_method(rb_cBigDecimal, "infinite?", BigDecimal_IsInfinite, 0);
rb_define_method(rb_cBigDecimal, "finite?", BigDecimal_IsFinite, 0);
rb_define_method(rb_cBigDecimal, "truncate", BigDecimal_truncate, -1);
numeric.c
return num;
}
/*
* call-seq:
* num.exact? -> true or false
*
* Returns +true+ if +num+ is an exact number, otherwise returns +false+.
*/
static VALUE
num_exact_p(VALUE num)
{
return Qtrue;
}
/*
* call-seq:
* num.finite? -> true or false
......
return isnan(value) ? Qtrue : Qfalse;
}
/*
* call-seq:
* float.exact? -> false
*
* Returns +false+, as floating point numbers are not exact.
*/
static VALUE
flo_is_exact_p(VALUE num)
{
return Qfalse;
}
/*
* call-seq:
* float.infinite? -> -1, 1, or nil
......
rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);
rb_define_method(rb_cNumeric, "exact?", num_exact_p, 0);
rb_define_method(rb_cNumeric, "finite?", num_finite_p, 0);
rb_define_method(rb_cNumeric, "infinite?", num_infinite_p, 0);
......
rb_define_method(rb_cFloat, "truncate", flo_truncate, -1);
rb_define_method(rb_cFloat, "nan?", flo_is_nan_p, 0);
rb_define_method(rb_cFloat, "exact?", flo_is_exact_p, 0);
rb_define_method(rb_cFloat, "infinite?", rb_flo_is_infinite_p, 0);
rb_define_method(rb_cFloat, "finite?", rb_flo_is_finite_p, 0);
rb_define_method(rb_cFloat, "next_float", flo_next_float, 0);
test/bigdecimal/test_bigdecimal.rb
assert_nan(BigDecimal("NaN").nonzero?)
end
def test_exact_p
assert_not_predicate(BigDecimal('0.0'), :exact?)
end
def test_double_fig
assert_kind_of(Integer, BigDecimal.double_fig)
end
test/ruby/test_complex.rb
assert_equal([true, true], [c.eql?(c1), c1.eql?(c)])
end
def test_exact_p
assert_predicate(Complex(1), :exact?)
assert_not_predicate(Complex(1, 1.0), :exact?)
assert_not_predicate(Complex(1.0, 1), :exact?)
assert_not_predicate(Complex(1.0, 1.0), :exact?)
end
def test_eql_p
c = Complex(0)
c2 = Complex(0)
test/ruby/test_float.rb
assert_equal(a == b, b == a)
end
def test_exact_p
assert_not_predicate(1.0, :exact?)
end
def test_cmp_int
100.times {|i|
int0 = 1 << i
test/ruby/test_integer.rb
end;
end
def test_exact_p
assert_predicate(1, :exact?)
end
def test_int_p
assert_not_predicate(1.0, :integer?)
assert_predicate(1, :integer?)
test/ruby/test_rational.rb
assert_equal([true, true], [c.eql?(c1), c1.eql?(c)])
end
def test_exact_p
assert_predicate(Rational(1), :exact?)
end
def test_eql_p
c = Rational(0)
c2 = Rational(0)
    (1-1/1)