るりまサーチ (Ruby 2.3.0)

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

別のキーワード

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

ライブラリ

クラス

検索結果

Rational#quo(other) -> Rational | Float (72667.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 ZeroD...

Numeric#quo(other) -> Rational | Float | Complex (54754.0)

self を other で割った商を返します。 整商を得たい場合は Numeric#div を使ってください。

self を other で割った商を返します。
整商を得たい場合は Numeric#div を使ってください。

Numeric#fdiv が結果を Float で返すメソッドなのに対して quo はなるべく正確な数値を返すことを意図しています。
具体的には有理数の範囲に収まる計算では Rational の値を返します。
Float や Complex が関わるときはそれらのクラスになります。

Numeric のサブクラスは、このメソッドを適切に再定義しなければなりません。


@param other 自身を割る数を指定します。

//emlist[例][ruby]{
1.quo(3)...

Rational#/(other) -> Rational | Float (27367.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 ZeroD...

Integer#/(other) -> Numeric (58.0)

除算の算術演算子。

除算の算術演算子。

other が Integer の場合、整商(整数の商)を Integer で返します。
普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。

other が Float、Rational、Complex の場合、普通の商を other と
同じクラスのインスタンスで返します。

@param other 二項演算の右側の引数(対象)
@return 計算結果

//emlist[例][ruby]{
7 / 2 # => 3
7 / -2 # => -4
7 / 2.0 # => 3.5
7 / Rational(2, 1) # => (7/2)
7...