static inline double num2dbl_with_to_f(VALUE num) { if (SPECIAL_CONST_P(num)) { if (FIXNUM_P(num)) { if (basic_to_f_p(rb_cFixnum)) return fix2dbl_without_to_f(num); } else if (FLONUM_P(num)) { return RFLOAT_VALUE(num); } } else { switch (BUILTIN_TYPE(num)) { case T_FLOAT: return RFLOAT_VALUE(num); case T_BIGNUM: if (basic_to_f_p(rb_cBignum)) return big2dbl_without_to_f(num); break; case T_RATIONAL: if (basic_to_f_p(rb_cRational)) return rat2dbl_without_to_f(num); break; } } return RFLOAT_VALUE(rb_to_float(num)); }
static int linear_object_p(VALUE obj) { if (FIXNUM_P(obj) || FLONUM_P(obj)) return TRUE; if (SPECIAL_CONST_P(obj)) return FALSE; switch (BUILTIN_TYPE(obj)) { case T_FLOAT: case T_BIGNUM: return TRUE; } if (rb_obj_is_kind_of(obj, rb_cNumeric)) return TRUE; if (rb_obj_is_kind_of(obj, rb_cTime)) return TRUE; return FALSE; }
/*! * \internal * Returns the singleton class of \a obj. Creates it if necessary. * * \note DO NOT expose the returned singleton class to * outside of class.c. * Use \ref rb_singleton_class instead for * consistency of the metaclass hierarchy. */ static VALUE singleton_class_of(VALUE obj) { VALUE klass; if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) { rb_raise(rb_eTypeError, "can't define singleton"); } if (SPECIAL_CONST_P(obj)) { klass = special_singleton_class_of(obj); if (NIL_P(klass)) rb_bug("unknown immediate %p", (void *)obj); return klass; } else { enum ruby_value_type type = BUILTIN_TYPE(obj); if (type == T_FLOAT || type == T_BIGNUM) { rb_raise(rb_eTypeError, "can't define singleton"); } } if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) && rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) { klass = RBASIC(obj)->klass; } else { klass = rb_make_metaclass(obj, RBASIC(obj)->klass); } if (OBJ_TAINTED(obj)) { OBJ_TAINT(klass); } else { FL_UNSET(klass, FL_TAINT); } if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass); return klass; }