るりまサーチ

最速Rubyリファレンスマニュアル検索!
981件ヒット [101-200件を表示] (0.076秒)

別のキーワード

  1. _builtin rational
  2. rational **
  3. json/add/rational to_json
  4. json/add/rational json_create
  5. rational /

ライブラリ

クラス

キーワード

検索結果

<< < 1 2 3 4 ... > >>

Rational#magnitude -> Rational (9115.0)

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

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

//emlist[例][ruby]{
Rational
(1, 2).abs # => (1/2)
Rational
(-1, 2).abs # => (1/2)
//}...

Rational#quo(other) -> Rational | Float (9115.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 (9114.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 (9114.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 (9114.0)

自身を返します。

...自身を返します。

@return 自身を返します。

//emlist[例][ruby]{
Rational
(3, 4).to_r # => (3/4)
Rational
(8).to_r # => (8/1)
//}...

絞り込み条件を変える

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

差を計算します。

...差を計算します。

@param other 自身から引く数

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

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

Rational#-@ -> Rational (9108.0)

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

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

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

Rational#to_i -> Integer (9074.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 (9049.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 (9049.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
(...

絞り込み条件を変える

<< < 1 2 3 4 ... > >>