種類
- インスタンスメソッド (84)
- 特異メソッド (2)
- 定数 (1)
ライブラリ
- ビルトイン (52)
-
bigdecimal
/ util (3) - mathn (6)
- rational (26)
キーワード
- % (1)
- * (3)
- ** (6)
- + (3)
- - (3)
-
/ (3) - <=> (3)
- == (3)
- Unify (1)
- abs (1)
- ceil (3)
- coerce (3)
- convert (2)
- denominator (3)
- div (1)
- divmod (1)
- fdiv (2)
- floor (3)
- hash (3)
- inspect (4)
-
marshal
_ dump (2) -
marshal
_ load (2) - new! (1)
- numerator (3)
- power2 (1)
- quo (2)
- rationalize (2)
- reduce (1)
- round (3)
-
to
_ d (3) -
to
_ f (3) -
to
_ i (3) -
to
_ r (3) -
to
_ s (3) - truncate (3)
検索結果
先頭5件
-
Rational
# %(other) -> Rational | Float (1) -
剰余を計算します。絶対値が self の絶対値を越えない、符号が self と同じ Numeric を返します。
...。絶対値が self の絶対値を越えない、符号が self と同じ
Numeric を返します。
@param other 自身を割る数
例:
Rational(3, 4) % 2 # => Rational(3, 4)
Rational(3, 4) % Rational(2, 1) # => Rational(3, 4)
Rational(3, 4) % 2.0 # => 0.75... -
Rational
# *(other) -> Rational | Float (1) -
積を計算します。
...例:
Rational(3, 4) * 2 # => Rational(3, 2)
Rational(3, 4) * 4 # => Rational(3, 1)
Rational(3, 4) * 0.5 # => 0.375
Rational(3, 4) * Rational(1, 2) # => Rational(3, 8)
other に 0 を指定した場合も Rational を返します。
Rational(3, 4) *......0 # => Rational(0, 1)......します。
@param other 自身に掛ける数
other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
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 (1) -
冪(べき)乗を計算します。
...した場合は、計算結果を Rational で返します。
other に整数以外を指定した場合は計算結果を Float で返します。
例:
Rational(3, 4) ** 2 # => Rational(9, 16)
Rational(3, 4) ** Rational(2, 1) # => 0.5625
Rational(3, 4) ** 2.0 # => 0.......5625
注意:
1.9 系とは計算結果のオブジェクトが異なる場合がある事に注意してください。
other に Rational を指定した場合には戻り値が Rational を返
す場合があります。
# 1.9.1 の場合
Rational(3, 4) ** Rational(2, 1) # => (9/16)......計算結果が無理数だった場合は Float
を返します。
例:
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
注意:
1.8 系とは計算結果のオブジェク......トが異なる場合がある事に注意してください。
other に Rational を指定した場合には戻り値は必ず Float を返
していました。
# 1.8.7 の場合
r = Rational(3, 4)
r ** Rational(2, 1) # => 0.5625... -
Rational
# **(rhs) -> Numeric (1) -
@todo
...@todo
self のべき乗を返します。 Rational になるようであれば Rational で返します。... -
Rational
# +(other) -> Rational | Float (1) -
和を計算します。
...算します。
@param other 自身に足す数
other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
Rational(3, 4) + 2 # => Rational(11, 4)
Rational(3, 4) + Rational(2, 1) # => Rational(11, 4)
Rational(3, 4) + 2.0 # => 2.75......。
@param other 自身に足す数
other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25... -
Rational
# -(other) -> Rational | Float (1) -
差を計算します。
...am other 自身から引く数
other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
Rational(3, 4) - 1 # => Rational(-1, 4)
Rational(3, 4) - 0.5 # => 0.25......ます。
@param other 自身から引く数
other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
r = Rational(3, 4)
r - 1 # => (-1/4)
r - 0.5 # => 0.25... -
Rational
# / (other) -> Rational | Float (1) -
商を計算します。
...定した場合は、計算結果を Float で返しま
す。
例:
Rational(3, 4) / 2 # => Rational(3, 8)
Rational(3, 4) / Rational(2, 1) # => Rational(3, 8)
Rational(3, 4) / 2.0 # => 0.375
Rational(3, 4) / 0 # => ZeroDivisionError
@raise ZeroDivision......other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
@raise ZeroDivisionError other が 0... -
Rational
# <=>(other) -> -1 | 0 | 1 | nil (1) -
self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。
...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) <=> nil # =>... -
Rational
# ==(other) -> bool (1) -
数値として等しいか判定します。
...します。
例:
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.new! で作成し......たオブジェクトと比較した場合、同じ数値を表
すオブジェクトでも true を返さない事があります。
Rational(1,2) == Rational(4,8) # => true
Rational(1,2) == Rational.new!(4,8) # => false
詳しくは Rational.new! を確認してください。......そうでなければ false を返します。
例:
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
# abs -> Rational (1) -
自身の絶対値を返します。
...自身の絶対値を返します。
例:
Rational(1, 2).abs.to_s # => 1/2
Rational(-1, 2).abs.to_s # => 1/2... -
Rational
# ceil -> Integer (1) -
自身と等しいかより大きな整数のうち最小のものを返します。
...しいかより大きな整数のうち最小のものを返します。
例:
Rational(3).ceil # => 3
Rational(2, 3).ceil # => 1
Rational(-3, 2).ceil # => -1
@see Rational#floor, Rational#round, Rational#truncate... -
Rational
# ceil(precision = 0) -> Integer | Rational (1) -
自身と等しいかより大きな整数のうち最小のものを返します。
...発生します。
例:
Rational(3).ceil # => 3
Rational(2, 3).ceil # => 1
Rational(-3, 2).ceil # => -1
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
例:
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
# coerce(other) -> Array (1) -
自身と other が同じクラスになるよう、自身か other を変換し [other, self] という 配列にして返します。
...other が同じクラスになるよう、自身か other を変換し [other, self] という
配列にして返します。
@param other 比較または変換するオブジェクト
例:
Rational(1).coerce(2) # => [Rational(2, 1), Rational(1, 1)]
Rational(1).coerce(2.2) # => [2.2, 1.0]......[other, self] という
配列にして返します。
@param other 比較または変換するオブジェクト
例:
Rational(1).coerce(2) # => [(2/1), (1/1)]
Rational(1).coerce(2.2) # => [2.2, 1.0]... -
Rational
# convert(*arg) -> Rational (1) -
引数を有理数(Rational)に変換した結果を返します。
...引数を有理数(Rational)に変換した結果を返します。
@param arg 変換対象のオブジェクトです。
Kernel.#Rational の本体です。
@see Kernel.#Rational... -
Rational
# denominator -> Integer (1) -
分母を返します。常に正の整数を返します。
...整数を返します。
@return 分母を返します。
例:
Rational(7).denominator # => 1
Rational(7, 1).denominator # => 1
Rational(9, -4).denominator # => 4
Rational(-2, -10).denominator # => 5
@see Rational#numerator... -
Rational
# div(other) -> Integer (1) -
self を other で割った整数の商を返します。
...self を other で割った整数の商を返します。
@param other 自身を割る数
例:
Rational(1, 2).div(Rational(2, 3)) # => 0... -
Rational
# divmod(other) -> [Integer , Float | Rational] (1) -
self を other で割った、商と余りの配列を返します。
...:
Rational(3,4).divmod(Rational(2,3)) # => [1, Rational(1, 12)]
Rational(-3,4).divmod(Rational(2,3)) # => [-2, Rational(7, 12)]
Rational(3,4).divmod(Rational(-2,3)) # => [-2, Rational(-7, 12)]
Rational(9,4).divmod(2) # => [1, Rational(1, 4)]
Rational(9,4).divmod(Rational(2,......1)) # => [1, Rational(1, 4)]
Rational(9,4).divmod(2.0) # => [1, 0.25]
@see Numeric#divmod... -
Rational
# fdiv(other) -> Float (1) -
自身を other で割った実数の商を返します。
...を other で割った実数の商を返します。
@param other 自身を割る数
例:
Rational(2, 3).fdiv(1) # => 0.6666666666666666
Rational(2, 3).fdiv(0.5) # => 1.3333333333333333
Rational(2).fdiv(3) # => 0.6666666666666666... -
Rational
# floor -> Integer (1) -
自身と等しいかより小さな整数のうち最大のものを返します。
...:
Rational(3).floor # => 3
Rational(2, 3).floor # => 0
Rational(-3, 2).floor # => -2
自身にもっとも近い整数を返す Rational#to_i とは違う結果を返す事に
注意してください。
例:
Rational(+7, 4).to_i # => 1
Rational(+7, 4).floor # => 1
Rational(-7,......4).to_i # => -1
Rational(-7, 4).floor # => -2
@see Rational#ceil, Rational#round, Rational#truncate... -
Rational
# floor(precision = 0) -> Integer | Rational (1) -
自身と等しいかより小さな整数のうち最大のものを返します。
...:
Rational(3).floor # => 3
Rational(2, 3).floor # => 0
Rational(-3, 2).floor # => -2
自身にもっとも近い整数を返す Rational#to_i とは違う結果を返す事に
注意してください。
例:
Rational(+7, 4).to_i # => 1
Rational(+7, 4).floor # => 1
Rational(-7,......=> -1
Rational(-7, 4).floor # => -2
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
例:
Rational('-123.456').floor(+1) # => (-247/2)
Rational('-123.456').floor(+1).to_f # => -123.5
Rational('-1......23.456').floor(0) # => -124
Rational('-123.456').floor(-1) # => -130
@see Rational#ceil, Rational#round, Rational#truncate... -
Rational
# hash -> Integer (1) -
自身のハッシュ値を返します。
自身のハッシュ値を返します。
@return ハッシュ値を返します。 -
Rational
# inspect (1) -
有理数値を人間が読みやすい形の文字列表現にして返します。
有理数値を人間が読みやすい形の文字列表現にして返します。
現在のバージョンでは "3/5", "-17/7" のように10進数の既約分数表記を返します。 -
Rational
# inspect -> String (1) -
自身を人間が読みやすい形の文字列表現にして返します。
...自身を"Rational(分子, 分母)" 形式の文字列にして返します。
@return 文字列を返します。
例:
Rational(5, 8).inspect # => "Rational(5, 8)"
Rational(2).inspect # => "Rational(2, 1)"
Rational(-8, 6).inspect # => "Rational(-4, 3)"
1.9系とは結果が異なる......事に注意してください。
# 1.9.1の場合
Rational(5, 8).inspect # => "(5/8)"
Rational(2).inspect # => "(2/1)"
Rational(-8, 6).inspect # => "(-4/3)"
@see Rational#to_s......)" のように10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
例:
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
# marshal _ dump -> Array (1) -
Rational#marshal_load で復元可能な配列を返します。
...
Rational#marshal_load で復元可能な配列を返します。
@see Rational#marshal_load... -
Rational
# marshal _ load -> Rational (1) -
Rational#marshal_dump で得られた配列を基に、Rational オブジェ クトを復元します。
...
Rational#marshal_dump で得られた配列を基に、Rational オブジェ
クトを復元します。
@see Rational#marshal_dump... -
Rational
# numerator -> Integer (1) -
分子を返します。
...分子を返します。
@return 分子を返します。
例:
Rational(7).numerator # => 7
Rational(7, 1).numerator # => 7
Rational(9, -4).numerator # => -9
Rational(-2, -10).numerator # => 1
@see Rational#denominator... -
Rational
# power2 (1) -
@todo
@todo -
Rational
# quo(other) -> Rational | Float (1) -
商を計算します。
...other に Float を指定した場合は、計算結果を Float で返しま
す。
例:
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
@raise ZeroDivisionError other が 0... -
Rational
# rationalize(eps = 0) -> Rational (1) -
自身から eps で指定した許容誤差の範囲に収まるような Rational を返 します。
...うな Rational を返
します。
eps を省略した場合は self を返します。
@param eps 許容する誤差
例:
r = Rational(5033165, 16777216)
r.rationalize # => (5033165/16777216)
r.rationalize(Rational(0.01)) # => (3/10)
r.rationalize(Rational(0.1))... -
Rational
# round -> Integer (1) -
自身ともっとも近い整数を返します。
...中央値 0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。
例:
Rational(3).round # => 3
Rational(2, 3).round # => 1
Rational(-3, 2).round # => -2
@see Rational#ceil, Rational#floor, Rational#truncate... -
Rational
# round(precision = 0) -> Integer | Rational (1) -
自身ともっとも近い整数を返します。
...発生します。
例:
Rational(3).round # => 3
Rational(2, 3).round # => 1
Rational(-3, 2).round # => -2
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。
例:
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
# to _ d(nFig = 0) -> BigDecimal (1) -
自身を BigDecimal に変換します。
...まで計算を行います。
@param nFig 計算を行う桁数
@return BigDecimal に変換したオブジェクト
例:
require "rational"
require "bigdecimal"
require "bigdecimal/util"
Rational(1, 3).to_d(3).to_s # => "0.333E0"
Rational(1, 3).to_d(10).to_s # => "0.3333333333E0"......imal に変換したオブジェクト
@raise ArgumentError nFig に負の数を指定した場合に発生します。
例:
require "rational"
require "bigdecimal"
require "bigdecimal/util"
Rational(1, 3).to_d(3).to_s # => "0.333E0"
Rational(1, 3).to_d(10).to_s # => "0.3333333333E0"... -
Rational
# to _ f -> Float (1) -
自身を Float に変換します。
...自身を Float に変換します。
@return 実数を返します。
例:
Rational(9, 4).to_f # => 2.25
Rational(-3, 4).to_f # => -0.75
Rational(20, 3).to_f # => 6.666666666666667......自身を Float に変換します。
@return 実数を返します。
例:
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
# to _ i -> Integer (1) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
...の整数で、自身にもっとも近い整数を返します。
例:
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(98, 71).to_i # => 1
Rational(-30, 2).to_i # => -15
@see Rational#ceil, Rational#floor......。
例:
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-30, 2).to_i # => -15
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返しま......す。
例:
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
# to _ r -> Rational (1) -
自身を返します。
自身を返します。
@return 自身を返します。 -
Rational
# to _ s -> String (1) -
自身を人間が読みやすい形の文字列表現にして返します。
...字列表現にして返します。
"3/5", "-17/7" のように10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
例:
Rational(-3, 4).to_s # => "-3/4"
Rational(8).to_s # => "8"
Rational(-8, 6).to_s # => "-4/3"
@see Rational#inspect......。
"3/5", "-17/7" のように10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
例:
Rational(3, 4).to_s # => "3/4"
Rational(8).to_s # => "8"
Rational(-8, 6).to_s # => "-4/3"
Rational(0.5).to_s # => "1/2"
@see Rational#inspect... -
Rational
# truncate -> Integer (1) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
...の整数で、自身にもっとも近い整数を返します。
例:
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(98, 71).to_i # => 1
Rational(-30, 2).to_i # => -15
@see Rational#ceil, Rational#floor... -
Rational
# truncate(precision = 0) -> Rational | Integer (1) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
...。
例:
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-30, 2).to_i # => -15
precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返しま......す。
例:
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
. new!(num , den = 1) -> Rational (1) -
Rational オブジェクトを生成します。
...
Rational オブジェクトを生成します。
@param num 分子を指定します。
@param den 分母を指定します。省略した場合は 1 です。
Kernel#Rational とは異なり、約分していない Rational オブジェ
クトを返します。
例:
Rational.new!(1, 3)......# => Rational(1, 3)
Rational.new!(2, 6) # => Rational(2, 6)
また、引数のチェックも行われません。
例:
Rational.new!(1, 0) # => Rational(1, 0)
Rational(1, 0) # => ZeroDivisionError
注意:
Rational.new! は 1.9系 では廃止されまし......た。Kernel.#Rational の方
を使用してください。
# 1.9.1 の場合
Rational.new!(1, 3) # => NoMethodError... -
Rational
. reduce(num , den = 1) -> Rational (1) -
約分された Rational オブジェクトを生成します。
...約分された Rational オブジェクトを生成します。
@param num 分子を指定します。
@param den 分母を指定します。省略した場合は 1 です。
@raise ZeroDivisionError den に 0 を指定した場合に発生します。
引数 num、den の両方を指定した......た
Rational オブジェクトを返します。
Kernel#Rational とは異なり、num と den には整数しか指定できません。
例:
Rational.reduce(2, 6) # => Rational(1, 3)
Rational.reduce(Rational(1, 3), 1) # => NoMethodError: undefined method `gcd' for Rational(1,......3):Rational
注意:
Rational.reduce は 1.9 系 では廃止されました。Kernel.#Rational の
方を使用してください。
# 1.9.1 の場合
Rational.reduce(2, 6) # => NoMethodError... -
Rational
:: Unify (1) -
内部実装で利用しています。深くは考えないでください。ユーザープログラムでは利用しないでください。
内部実装で利用しています。深くは考えないでください。ユーザープログラムでは利用しないでください。
この定数はRuby 1.9.1以降では削除されます。
