るりまサーチ

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

キーワード

検索結果

<< 1 2 3 > >>

Rational#-@ -> Rational (6103.0)

単項演算子の - です。 self の符号を反転させたものを返します。

...単項演算子の - です。
self の符号を反転させたものを返します。

//emlist[例][ruby]{
r = Rational(3, 4)
- r # => (-3/4)
//}...

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

商を計算します。

...算します。

@
param other 自身を割る数

other に Float を指定した場合は、計算結果を 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 ZeroDivisionError other が 0 の時に発生します。

@
see Numeric#quo...

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

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

...うち最小のものを返します。

@
param precision 計算結果の精度

@
raise TypeError precision に整数以外のものを指定すると発生します。

//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#trunc...

Rational#floor(precision = 0) -> Integer | Rational (21.0)

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

...ものを返します。

@
param precision 計算結果の精度

@
raise TypeError precision に整数以外のものを指定すると発生します。

//emlist[例][ruby]{
Rational
(3).floor # => 3
Rational
(2, 3).floor # => 0
Rational
(-3, 2).floor # => -2
//}

Rational
#to_i とは違う結...
...uby]{
Rational
(+7, 4).to_i # => 1
Rational
(+7, 4).floor # => 1
Rational
(-7, 4).to_i # => -1
Rational
(-7, 4).floor # => -2
//}

precision を指定した場合は指定した桁数の数値と、上述の性質に最も近い整
数か Rational を返します。

//emlist[例][ruby]{
Rational
('-12...
...3.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#truncate...

Rational#quo(other) -> Rational | Float (21.0)

商を計算します。

...算します。

@
param other 自身を割る数

other に Float を指定した場合は、計算結果を 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 ZeroDivisionError other が 0 の時に発生します。

@
see Numeric#quo...

絞り込み条件を変える

Rational#round(precision = 0) -> Integer | Rational (21.0)

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

...れ 1,-1 に切り上げされます。

@
param precision 計算結果の精度

@
raise TypeError precision に整数以外のものを指定すると発生します。

//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#to_i -> Integer (21.0)

小数点以下を切り捨てて値を整数に変換します。

...ます。

@
param precision 計算結果の精度

@
raise TypeError precision に整数以外のものを指定すると発生します。

//emlist[例][ruby]{
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...
...
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#truncate(precision = 0) -> Rational | Integer (21.0)

小数点以下を切り捨てて値を整数に変換します。

...ます。

@
param precision 計算結果の精度

@
raise TypeError precision に整数以外のものを指定すると発生します。

//emlist[例][ruby]{
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...
...
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 (15.0)

self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。

...nilを返します。

@
param other 自身と比較する数値

@
return -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#==(other) -> bool (15.0)

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

...

@
param other 自身と比較する数値

@
return self と other が等しい場合 true を返します。
そうでなければ 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
//}...

絞り込み条件を変える

<< 1 2 3 > >>