本文簡要介紹ruby語言中 Rational.rational
的用法。
用法
rational <=> numeric → -1, 0, +1, or nil
根據 rational
是小於、等於還是大於 numeric
返回 -1、0 或 +1。
如果兩個值不可比較,則返回 nil
。
Rational(2, 3) <=> Rational(2, 3) #=> 0
Rational(5) <=> 5 #=> 0
Rational(2, 3) <=> Rational(1, 3) #=> 1
Rational(1, 3) <=> 1 #=> -1
Rational(1, 3) <=> 0.3 #=> 1
Rational(1, 3) <=> "0.3" #=> nil
相關用法
- Ruby Rational.rationalize用法及代碼示例
- Ruby Rational.rat ** numeric用法及代碼示例
- Ruby Rational.rat * numeric用法及代碼示例
- Ruby Rational.rat / numeric用法及代碼示例
- Ruby Rational.rat + numeric用法及代碼示例
- Ruby Rational.rat - numeric用法及代碼示例
- Ruby Rational.rat ==用法及代碼示例
- Ruby Rational.round用法及代碼示例
- Ruby Rational.inspect用法及代碼示例
- Ruby Rational.denominator用法及代碼示例
- Ruby Rational.ceil用法及代碼示例
- Ruby Rational.floor用法及代碼示例
- Ruby Rational.fdiv用法及代碼示例
- Ruby Rational.truncate用法及代碼示例
- Ruby Rational.magnitude用法及代碼示例
- Ruby Rational.abs用法及代碼示例
- Ruby Rational.to_f用法及代碼示例
- Ruby Rational.quo用法及代碼示例
- Ruby Rational.to_s用法及代碼示例
- Ruby Rational.to_r用法及代碼示例
- Ruby Rational.to_d用法及代碼示例
- Ruby Rational.to_i用法及代碼示例
- Ruby Rational.numerator用法及代碼示例
- Ruby Rational to_i()用法及代碼示例
- Ruby Rational quo()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Rational.rational <=>。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。