Method: Rational#-

Defined in:
rational.c

#-(numeric) ⇒ Numeric

Performs subtraction.

Rational(2, 3)  - Rational(2, 3)   #=> (0/1)
Rational(900)   - Rational(1)      #=> (899/1)
Rational(-2, 9) - Rational(-9, 2)  #=> (77/18)
Rational(9, 8)  - 4                #=> (-23/8)
Rational(20, 9) - 9.8              #=> -7.577777777777778

Returns:



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'rational.c', line 770

VALUE
rb_rational_minus(VALUE self, VALUE other)
{
    if (RB_INTEGER_TYPE_P(other)) {
        {
            get_dat1(self);

            return f_rational_new_no_reduce2(CLASS_OF(self),
                                             rb_int_minus(dat->num, rb_int_mul(other, dat->den)),
                                             dat->den);
        }
    }
    else if (RB_FLOAT_TYPE_P(other)) {
        return DBL2NUM(nurat_to_double(self) - RFLOAT_VALUE(other));
    }
    else if (RB_TYPE_P(other, T_RATIONAL)) {
        {
            get_dat2(self, other);

            return f_addsub(self,
                            adat->num, adat->den,
                            bdat->num, bdat->den, '-');
        }
    }
    else {
        return rb_num_coerce_bin(self, other, '-');
    }
}