Example #1
0
inline static VALUE
f_zero_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) == 0);
    return rb_funcall(x, id_equal_p, 1, ZERO);
}
Example #2
0
static VALUE
nurat_equal_p(VALUE self, VALUE other)
{
    switch (TYPE(other)) {
      case T_FIXNUM:
      case T_BIGNUM:
	{
	    get_dat1(self);

	    if (!FIXNUM_P(dat->den))
		return Qfalse;
	    if (FIX2LONG(dat->den) != 1)
		return Qfalse;
	    if (f_equal_p(dat->num, other))
		return Qtrue;
	    else
		return Qfalse;
	}
      case T_FLOAT:
	return f_equal_p(f_to_f(self), other);
      case T_RATIONAL:
	{
	    get_dat2(self, other);

	    return f_boolcast(f_equal_p(adat->num, bdat->num) &&
			      f_equal_p(adat->den, bdat->den));
	}
      default:
	return f_equal_p(other, self);
    }
}
Example #3
0
inline static VALUE
f_negative_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) < 0);
    return rb_funcall(x, '<', 1, ZERO);
}
Example #4
0
inline static VALUE
f_eqeq_p(VALUE x, VALUE y)
{
    if (FIXNUM_P(x) && FIXNUM_P(y))
	return f_boolcast(FIX2LONG(x) == FIX2LONG(y));
    return rb_funcall(x, id_eqeq_p, 1, y);
}
Example #5
0
inline static VALUE
f_zero_p(VALUE x)
{
    if (RB_TYPE_P(x, T_FIXNUM)) {
	return f_boolcast(FIX2LONG(x) == 0);
    }
    else if (RB_TYPE_P(x, T_BIGNUM)) {
	return Qfalse;
    }
    else if (RB_TYPE_P(x, T_RATIONAL)) {
	VALUE num = RRATIONAL(x)->num;

	return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
    }
    return rb_funcall(x, id_eqeq_p, 1, ZERO);
}
Example #6
0
inline static VALUE
f_gt_p(VALUE x, VALUE y)
{
    if (FIXNUM_P(x) && FIXNUM_P(y))
	return f_boolcast(FIX2LONG(x) > FIX2LONG(y));
    return rb_funcall(x, '>', 1, y);
}
Example #7
0
inline static VALUE
f_one_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) == 1);
    return rb_funcall(x, id_equal_p, 1, ONE);
}
Example #8
0
/*
 * call-seq:
 *    cmp == object  ->  true or false
 *
 * Returns true if cmp equals object numerically.
 *
 *    Complex(2, 3)  == Complex(2, 3)   #=> true
 *    Complex(5)     == 5               #=> true
 *    Complex(0)     == 0.0             #=> true
 *    Complex('1/3') == 0.33            #=> false
 *    Complex('1/2') == '1/2'           #=> false
 */
static VALUE
nucomp_eqeq_p(VALUE self, VALUE other)
{
    if (k_complex_p(other)) {
	get_dat2(self, other);

	return f_boolcast(f_eqeq_p(adat->real, bdat->real) &&
			  f_eqeq_p(adat->imag, bdat->imag));
    }
    if (k_numeric_p(other) && f_real_p(other)) {
	get_dat1(self);

	return f_boolcast(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
    }
    return f_eqeq_p(other, self);
}
Example #9
0
inline static VALUE
f_zero_p(VALUE x)
{
    switch (TYPE(x)) {
      case T_FIXNUM:
	return f_boolcast(FIX2LONG(x) == 0);
      case T_BIGNUM:
	return Qfalse;
      case T_RATIONAL:
      {
	  VALUE num = RRATIONAL(x)->num;

	  return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
      }
    }
    return rb_funcall(x, id_eqeq_p, 1, ZERO);
}
Example #10
0
inline static VALUE
f_signbit(VALUE x)
{
    if (RB_TYPE_P(x, T_FLOAT)) {
        double f = RFLOAT_VALUE(x);
        return f_boolcast(!isnan(f) && signbit(f));
    }
    return f_negative_p(x);
}
Example #11
0
inline static VALUE
f_one_p(VALUE x)
{
    if (RB_TYPE_P(x, T_FIXNUM)) {
	return f_boolcast(FIX2LONG(x) == 1);
    }
    else if (RB_TYPE_P(x, T_BIGNUM)) {
	return Qfalse;
    }
    else if (RB_TYPE_P(x, T_RATIONAL)) {
	VALUE num = RRATIONAL(x)->num;
	VALUE den = RRATIONAL(x)->den;

	return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 1 &&
			  FIXNUM_P(den) && FIX2LONG(den) == 1);
    }
    return rb_funcall(x, id_eqeq_p, 1, ONE);
}
Example #12
0
inline static VALUE
f_lt_p(VALUE x, VALUE y)
{
    VALUE r;
    if (FIXNUM_P(x) && FIXNUM_P(y))
	r = f_boolcast(FIX2LONG(x) < FIX2LONG(y));
    else
	r = rb_funcall(x, '<', 1, y);
    return r;
}
Example #13
0
inline static VALUE
f_negative_p(VALUE x)
{
    VALUE r;
    if (FIXNUM_P(x))
	r = f_boolcast(FIX2LONG(x) < 0);
    else
	r = rb_funcall(x, '<', 1, ZERO);
    return r;
}
Example #14
0
inline static VALUE
f_equal_p(VALUE x, VALUE y)
{
    VALUE r;
    if (FIXNUM_P(x) && FIXNUM_P(y))
	r = f_boolcast(FIX2LONG(x) == FIX2LONG(y));
    else
	r = rb_funcall(x, id_equal_p, 1, y);
    return r;
}
Example #15
0
inline static VALUE
f_one_p(VALUE x)
{
    VALUE r;
    if (FIXNUM_P(x))
	r = f_boolcast(FIX2LONG(x) == 1);
    else
	r = rb_funcall(x, id_equal_p, 1, ONE);
    return r;
}
Example #16
0
inline static VALUE
f_zero_p(VALUE x)
{
    VALUE r;
    if (FIXNUM_P(x))
	r = f_boolcast(FIX2LONG(x) == 0);
    else
	r = rb_funcall(x, id_equal_p, 1, ZERO);
    return r;
}
Example #17
0
inline static VALUE
f_one_p(VALUE x)
{
    switch (TYPE(x)) {
      case T_FIXNUM:
	return f_boolcast(FIX2LONG(x) == 1);
      case T_BIGNUM:
	return Qfalse;
      case T_RATIONAL:
      {
	  VALUE num = RRATIONAL(x)->num;
	  VALUE den = RRATIONAL(x)->den;

	  return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 1 &&
			    FIXNUM_P(den) && FIX2LONG(den) == 1);
      }
    }
    return rb_funcall(x, id_eqeq_p, 1, ONE);
}
Example #18
0
inline static VALUE
f_signbit(VALUE x)
{
    switch (TYPE(x)) {
      case T_FLOAT: {
	double f = RFLOAT_VALUE(x);
	return f_boolcast(!isnan(f) && signbit(f));
      }
    }
    return f_negative_p(x);
}
Example #19
0
inline static VALUE
f_signbit(VALUE x)
{
#if defined(HAVE_SIGNBIT) && defined(__GNUC__) && defined(__sun) && \
    !defined(signbit)
    extern int signbit(double);
#endif
    if (RB_TYPE_P(x, T_FLOAT)) {
	double f = RFLOAT_VALUE(x);
	return f_boolcast(!isnan(f) && signbit(f));
    }
    return f_negative_p(x);
}
Example #20
0
/* :nodoc: */
static VALUE
nucomp_eql_p(VALUE self, VALUE other)
{
    if (k_complex_p(other)) {
	get_dat2(self, other);

	return f_boolcast((CLASS_OF(adat->real) == CLASS_OF(bdat->real)) &&
			  (CLASS_OF(adat->imag) == CLASS_OF(bdat->imag)) &&
			  f_eqeq_p(self, other));

    }
    return Qfalse;
}
Example #21
0
inline static VALUE
f_signbit(VALUE x)
{
    switch (TYPE(x)) {
      case T_FLOAT:
#ifdef HAVE_SIGNBIT
      {
	  double f = RFLOAT_VALUE(x);
	  return f_boolcast(!isnan(f) && signbit(f));
      }
#else
      {
	  char s[2];
	  double f = RFLOAT_VALUE(x);

	  if (isnan(f)) return Qfalse;
	  (void)snprintf(s, sizeof s, "%.0f", f);
	  return f_boolcast(s[0] == '-');
      }
#endif
    }
    return f_negative_p(x);
}
Example #22
0
inline static VALUE
f_tpositive_p(VALUE x)
{
    return f_boolcast(!f_signbit(x));
}
Example #23
0
/* :nodoc: */
static VALUE
nucomp_inexact_p(VALUE self)
{
    return f_boolcast(!nucomp_exact_p(self));
}
Example #24
0
/* :nodoc: */
static VALUE
nucomp_exact_p(VALUE self)
{
    get_dat1(self);
    return f_boolcast(k_exact_p(dat->real) && k_exact_p(dat->imag));
}