るりまサーチ

最速Rubyリファレンスマニュアル検索!
43件ヒット [1-43件を表示] (0.064秒)
トップページ > クラス:Rational[x] > クエリ:/[x]

関連するキーワード

  1. _builtin
  2. mathn
  3. matrix
  4. bignum
  5. bigdecimal

ライブラリ

キーワード

検索結果

Rational#/(other) -> Rational | Float (18137)

商を計算します。

...た場合は、計算結果を 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 ZeroDivisionError...
...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#quo(other) -> Rational | Float (3037)

商を計算します。

...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#inspect -> String (37)

自身を人間が読みやすい形の文字列表現にして返します。

..."(3/5)", "(-17/7)" のように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)"

@s...

Rational#to_s -> String (31)

自身を人間が読みやすい形の文字列表現にして返します。

...字列表現にして返します。

"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#*(other) -> Rational | Float (19)

積を計算します。

...します。

@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) -> bool (19)

数値として等しいか判定します。

...そうでなければ 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#inspect -> String (19)

自身を"Rational(分子, 分母)" 形式の文字列にして返します。

...自身を"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...

Rational#rationalize(eps = 0) -> Rational (19)

自身から 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))...
...# => (1/3)...

Rational#**(other) -> Rational | Float (13)

冪(べき)乗を計算します。

...計算結果が無理数だった場合は 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#+(other) -> Rational | Float (13)

和を計算します。

...足す数

other に Float を指定した場合は、計算結果を Float で返しま
す。

例:

r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25...

絞り込み条件を変える

Rational#abs -> Rational (13)

自身の絶対値を返します。

...自身の絶対値を返します。

例:

Rational
(1, 2).abs.to_s # => 1/2
Rational
(-1, 2).abs.to_s # => 1/2...

Rational#coerce(other) -> Array (13)

自身と other が同じクラスになるよう、自身か other を変換し [other, self] という 配列にして返します。

...[other, self] という
配列にして返します。

@param other 比較または変換するオブジェクト

例:

Rational
(1).coerce(2) # => [(2/1), (1/1)]
Rational
(1).coerce(2.2) # => [2.2, 1.0]...

Rational#inspect (13)

有理数値を人間が読みやすい形の文字列表現にして返します。

...有理数値を人間が読みやすい形の文字列表現にして返します。

現在のバージョンでは "3/5", "-17/7" のように10進数の既約分数表記を返します。...

Rational#**(other) -> Rational | Float (7)

冪(べき)乗を計算します。

...した場合は、計算結果を 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)...

Rational#-(other) -> Rational | Float (7)

差を計算します。

...other 自身から引く数

other に Float を指定した場合は、計算結果を Float で返しま
す。

例:

r = Rational(3, 4)
r - 1 # => (-1/4)
r - 0.5 # => 0.25...

絞り込み条件を変える

Rational#==(other) -> bool (7)

数値として等しいか判定します。

...します。

例:

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! を確認してください。...

Rational#ceil(precision = 0) -> Integer | Rational (7)

自身と等しいかより大きな整数のうち最小のものを返します。

...例:

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#floor(precision = 0) -> Integer | Rational (7)

自身と等しいかより小さな整数のうち最大のものを返します。

...:

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#round(precision = 0) -> Integer | Rational (7)

自身ともっとも近い整数を返します。

...例:

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 (7)

自身を 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_i -> Integer (7)

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#truncate(precision = 0) -> Rational | Integer (7)

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.reduce(num, den = 1) -> Rational (7)

約分された Rational オブジェクトを生成します。

... Rational オブジェクトを生成します。

@param num 分子を指定します。

@param den 分母を指定します。省略した場合は 1 です。

@raise ZeroDivisionError den に 0 を指定した場合に発生します。

引数 num、den の両方を指定した場合、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...