別のキーワード
キーワード
- * (1)
- ** (1)
- + (1)
- - (1)
- -@ (1)
-
/ (1) - <=> (1)
- == (1)
- abs (1)
- ceil (1)
- coerce (1)
- convert (1)
- denominator (1)
- fdiv (1)
- floor (1)
- hash (1)
- inspect (1)
- magnitude (1)
-
marshal
_ dump (1) - negative? (1)
- numerator (1)
- positive? (1)
- quo (1)
- rationalize (1)
- round (1)
-
to
_ f (1) -
to
_ i (1) -
to
_ r (1) -
to
_ s (1) - truncate (1)
検索結果
先頭5件
-
Rational
# rationalize(eps = 0) -> Rational (45718.0) -
自身から eps で指定した許容誤差の範囲に収まるような Rational を返 します。
...な Rational を返
します。
eps を省略した場合は self を返します。
@param eps 許容する誤差
//emlist[例][ruby]{
r = Rational(5033165, 16777216)
r.rationalize # => (5033165/16777216)
r.rationalize(Rational(0.01)) # => (3/10)
r.rationalize(Rational(0.1))... -
Rational
# floor(precision = 0) -> Integer | Rational (27604.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...[ruby]{
Rational(3).floor # => 3
Rational(2, 3).floor # => 0
Rational(-3, 2).floor # => -2
//}
Rational#to_i とは違う結果を返す事に注意してください。
//emlist[例][ruby]{
Rational(+7, 4).to_i # => 1
Rational(+7, 4).floor # => 1
Rational(-7, 4).to_i # => -1
Rational(-7, 4......か Rational を返します。
//emlist[例][ruby]{
Rational('-123.456').floor(+1) # => (-247/2)
Rational('-123.456').floor(+1).to_f # => -123.5
Rational('-123.456').floor(0) # => -124
Rational('-123.456').floor(-1) # => -130
//}
@see Rational#ceil, Rational#round, Rational#tr... -
Rational
# round(precision = 0) -> Integer | Rational (27532.0) -
自身ともっとも近い整数を返します。
...//emlist[例][ruby]{
Rational(3).round # => 3
Rational(2, 3).round # => 1
Rational(-3, 2).round # => -2
//}
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
//emlist[例][ruby]{
Rational('-123.456').round(+......1) # => (-247/2)
Rational('-123.456').round(+1).to_f # => -123.5
Rational('-123.456').round(0) # => -123
Rational('-123.456').round(-1) # => -120
Rational('-123.456').round(-2) # => -100
//}
@see Rational#ceil, Rational#floor, Rational#truncate... -
Rational
# truncate(precision = 0) -> Rational | Integer (27532.0) -
小数点以下を切り捨てて値を整数に変換します。
...by]{
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-31, 2).to_i # => -15
//}
precision を指定した場合は指定した桁数で切り捨てた整数か
Rational を返します。
//emlist[例][ruby]{
Rational('-......123.456').truncate(+1) # => (-617/5)
Rational('-123.456').truncate(+1).to_f # => -123.4
Rational('-123.456').truncate(0) # => -123
Rational('-123.456').truncate(-1) # => -120
//}
@see Rational#ceil, Rational#floor... -
Rational
# ceil(precision = 0) -> Integer | Rational (27514.0) -
自身と等しいかより大きな整数のうち最小のものを返します。
...//emlist[例][ruby]{
Rational(3).ceil # => 3
Rational(2, 3).ceil # => 1
Rational(-3, 2).ceil # => -1
//}
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
//emlist[例][ruby]{
Rational('-123.456').ceil(+1......) # => (-617/5)
Rational('-123.456').ceil(+1).to_f # => -123.4
Rational('-123.456').ceil(0) # => -123
Rational('-123.456').ceil(-1) # => -120
//}
@see Rational#floor, Rational#round, Rational#truncate... -
Rational
# convert(*arg) -> Rational (27400.0) -
引数を有理数(Rational)に変換した結果を返します。
...引数を有理数(Rational)に変換した結果を返します。
@param arg 変換対象のオブジェクトです。
Kernel.#Rational の本体です。
@see Kernel.#Rational... -
Rational
# **(other) -> Rational | Float (27370.0) -
冪(べき)乗を計算します。
...す。other が有理数であっても、計算結果が無理数だった場合は Float
を返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r ** Rational(2, 1) # => (9/16)
r ** 2 # => (9/16)
r ** 2.0 # => 0.5625
r ** Rational(1, 2) # => 0.866025403784439
//}... -
Rational
# / (other) -> Rational | Float (27355.0) -
商を計算します。
...定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionErr... -
Rational
# abs -> Rational (27355.0) -
自身の絶対値を返します。
...自身の絶対値を返します。
//emlist[例][ruby]{
Rational(1, 2).abs # => (1/2)
Rational(-1, 2).abs # => (1/2)
//}... -
Rational
# magnitude -> Rational (27355.0) -
自身の絶対値を返します。
...自身の絶対値を返します。
//emlist[例][ruby]{
Rational(1, 2).abs # => (1/2)
Rational(-1, 2).abs # => (1/2)
//}... -
Rational
# quo(other) -> Rational | Float (27355.0) -
商を計算します。
...定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionErr... -
Rational
# *(other) -> Rational | Float (27352.0) -
積を計算します。
...。
@param other 自身に掛ける数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r * 2 # => (3/2)
r * 4 # => (3/1)
r * 0.5 # => 0.375
r * Rational(1, 2) # => (3/8)
//}... -
Rational
# +(other) -> Rational | Float (27352.0) -
和を計算します。
...和を計算します。
@param other 自身に足す数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25
//}... -
Rational
# to _ r -> Rational (27352.0) -
自身を返します。
...自身を返します。
@return 自身を返します。
//emlist[例][ruby]{
Rational(3, 4).to_r # => (3/4)
Rational(8).to_r # => (8/1)
//}... -
Rational
# -(other) -> Rational | Float (27334.0) -
差を計算します。
...差を計算します。
@param other 自身から引く数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r - 1 # => (-1/4)
r - 0.5 # => 0.25
//}... -
Rational
# -@ -> Rational (27334.0) -
単項演算子の - です。 self の符号を反転させたものを返します。
...単項演算子の - です。
self の符号を反転させたものを返します。
//emlist[例][ruby]{
r = Rational(3, 4)
- r # => (-3/4)
//}... -
Rational
# to _ i -> Integer (27232.0) -
小数点以下を切り捨てて値を整数に変換します。
...by]{
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-31, 2).to_i # => -15
//}
precision を指定した場合は指定した桁数で切り捨てた整数か
Rational を返します。
//emlist[例][ruby]{
Rational('-......123.456').truncate(+1) # => (-617/5)
Rational('-123.456').truncate(+1).to_f # => -123.4
Rational('-123.456').truncate(0) # => -123
Rational('-123.456').truncate(-1) # => -120
//}
@see Rational#ceil, Rational#floor... -
Rational
# <=>(other) -> -1 | 0 | 1 | nil (27157.0) -
self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。
...返します。
//emlist[例][ruby]{
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) <=> nil # => nil
/... -
Rational
# to _ f -> Float (27157.0) -
自身の値を最も良く表現する Float に変換します。
...{
Rational(2).to_f # => 2.0
Rational(9, 4).to_f # => 2.25
Rational(-3, 4).to_f # => -0.75
Rational(20, 3).to_f # => 6.666666666666667
Rational(1, 10**1000).to_f # => 0.0
Rational(-1, 10**1000).to_f # => -0.0
Rational(10**1000).to_f # => Infinity
Rational(... -
Rational
# ==(other) -> bool (27121.0) -
数値として等しいか判定します。
...でなければ false を返します。
//emlist[例][ruby]{
Rational(2, 3) == Rational(2, 3) # => true
Rational(5) == 5 # => true
Rational(0) == 0.0 # => true
Rational('1/3') == 0.33 # => false
Rational('1/2') == '1/2' # => false
//}... -
Rational
# denominator -> Integer (27103.0) -
分母を返します。常に正の整数を返します。
...分母を返します。常に正の整数を返します。
@return 分母を返します。
//emlist[例][ruby]{
Rational(7).denominator # => 1
Rational(7, 1).denominator # => 1
Rational(9, -4).denominator # => 4
Rational(-2, -10).denominator # => 5
//}
@see Rational#numerator... -
Rational
# fdiv(other) -> Float (27103.0) -
self を other で割った商を Float で返します。 other に虚数を指定することは出来ません。
...@param other 自身を割る数
//emlist[例][ruby]{
Rational(2, 3).fdiv(1) # => 0.6666666666666666
Rational(2, 3).fdiv(0.5) # => 1.3333333333333333
Rational(2).fdiv(3) # => 0.6666666666666666
Rational(1).fdiv(Complex(1, 0)) # => 1.0
Rational(1).fdiv(Complex(0, 1)) # => RangeError
//}... -
Rational
# inspect -> String (27103.0) -
自身を人間が読みやすい形の文字列表現にして返します。
...に10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
//emlist[例][ruby]{
Rational(5, 8).inspect # => "(5/8)"
Rational(2).inspect # => "(2/1)"
Rational(-8, 6).inspect # => "(-4/3)"
Rational(0.5).inspect # => "(1/2)"
//}
@see Rational#to_s... -
Rational
# numerator -> Integer (27103.0) -
分子を返します。
...分子を返します。
@return 分子を返します。
//emlist[例][ruby]{
Rational(7).numerator # => 7
Rational(7, 1).numerator # => 7
Rational(9, -4).numerator # => -9
Rational(-2, -10).numerator # => 1
//}
@see Rational#denominator... -
Rational
# to _ s -> String (27103.0) -
自身を人間が読みやすい形の文字列表現にして返します。
..."-17/7" のように10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
//emlist[例][ruby]{
Rational(3, 4).to_s # => "3/4"
Rational(8).to_s # => "8/1"
Rational(-8, 6).to_s # => "-4/3"
Rational(0.5).to_s # => "1/2"
//}
@see Rational#inspect... -
Rational
# marshal _ dump -> Array (27079.0) -
Marshal.#load のためのメソッドです。 Rational::compatible#marshal_load で復元可能な配列を返します。
...Marshal.#load のためのメソッドです。
Rational::compatible#marshal_load で復元可能な配列を返します。
[注意] Rational::compatible は通常の方法では参照する事ができません。... -
Rational
# negative? -> bool (27067.0) -
self が 0 未満の場合に true を返します。そうでない場合に false を返します。
...self が 0 未満の場合に true を返します。そうでない場合に false を返します。
//emlist[例][ruby]{
Rational(1, 2).negative? # => false
Rational(-1, 2).negative? # => true
//}
@see Rational#positive?... -
Rational
# positive? -> bool (27067.0) -
self が 0 より大きい場合に true を返します。そうでない場合に false を返します。
...self が 0 より大きい場合に true を返します。そうでない場合に false を返します。
//emlist[例][ruby]{
Rational(1, 2).positive? # => true
Rational(-1, 2).positive? # => false
//}
@see Rational#negative?... -
Rational
# coerce(other) -> Array (27049.0) -
自身と other が同じクラスになるよう、自身か other を変換し [other, self] という 配列にして返します。
...other が同じクラスになるよう、自身か other を変換し [other, self] という
配列にして返します。
@param other 比較または変換するオブジェクト
//emlist[例][ruby]{
Rational(1).coerce(2) # => [(2/1), (1/1)]
Rational(1).coerce(2.2) # => [2.2, 1.0]
//}... -
Rational
# hash -> Integer (27013.0) -
自身のハッシュ値を返します。
自身のハッシュ値を返します。
@return ハッシュ値を返します。
@see Object#hash