るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

Numeric (44202.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...値を表す抽象クラスです。Integer や Float などの数値クラス
Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッド...
...提供されているメソッド
(+, -, *, /, %) を利用して定義されるものがほとんどです。
つまり Numeric で定義されているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce...
...それぞ
れのクラスを参照してください。


=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Numeric
Integer Fixnum Bignum Float Rational Complex
---------------------------------------------------------------------...
...かはそれぞ
れのクラスを参照してください。


=> ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin15]
Numeric
Integer Float Rational Complex
--------------------------------------------------------------------------------...

Numeric#i -> Complex (39155.0)

Complex(0, self) を返します。

...Complex(0, self) を返します。

ただし、Complex オブジェクトでは利用できません。

//emlist[例][ruby]{
10.i # => (0+10i)
-10.i # => (0-10i)
(0.1).i # => (0+0.1i)
Rational
(1, 2).i # => (0+(1/2)*i)
//}...

Numeric#denominator -> Integer (27228.0)

自身を Rational に変換した時の分母を返します。

...自身を Rational に変換した時の分母を返します。

@return 分母を返します。


@see Numeric#numerator、Integer#denominator、Float#denominator、Rational#denominator、Complex#denominator...

Numeric#to_int -> Integer (27228.0)

self.to_i と同じです。

...self.to_i と同じです。

//emlist[例][ruby]{
(2+0i).to_int # => 2
Rational
(3).to_int # => 3
//}...

Numeric#finite? -> bool (27118.0)

self の絶対値が有限値の場合に true を、そうでない場合に false を返します。

...値の場合に true を、そうでない場合に false を返します。

//emlist[例][ruby]{
10.finite? # => true
Rational
(3).finite? # => true

Float::INFINITY.finite? # => false
Float::INFINITY.is_a?(Numeric) # => true
//}

@see Numeric#infinite?...

絞り込み条件を変える

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

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

...を得たい場合は Numeric#div を使ってください。

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

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


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

//emlist[例][ruby]{
1.quo(3) #=> (1/3)
1.0.quo(3) #=> 0.333333...
...3333333333
1.quo(3.0) #=> 0.3333333333333333
1.quo(0.5) #=> 2.0

Complex(1, 1).quo(1) #=> ((1/1)+(1/1)*i)
1.quo(Complex(1, 1)) #=> ((1/2)-(1/2)*i)
//}

@see Numeric#fdiv...

Numeric#coerce(other) -> [Numeric] (24243.0)

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

...
Numeric
のサブクラスは、このメソッドを適切に再定義しなければなりません。
以下は Rational の coerce のソースです。other が自身の知らない数値クラスであった場合、
super を呼んでいることに注意して下さい。


//emlist[例]...
...[ruby]{
# lib/rational.rb より

def coerce(other)
i
f other.kind_of?(Float)
return other, self.to_f
elsif other.kind_of?(Integer)
return Rational.new!(other, 1), self
else
super
end
end
//}

数値クラスの算術演算子は通常自分と演算できないクラスをオペ...
... Rational の + メソッドを一部省略したものです。
引数が自身の知らない数値クラスである場合、引数の coerce により自身を変換してから
+ 演算子を呼んでいます。

//emlist[例][ruby]{
# lib/rational.rb より

def + (a)
i
f a.kind_of?(Rational...

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

商を計算します。

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

商を計算します。

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

Numeric#real -> Numeric (24219.0)

自身を返します。

...します。

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

//emlist[例][ruby]{
10.real # => 10
-10.real # => -10
0.1.real # => 0.1
Rational
(2, 3).real # => (2/3)
//}

@see Numeric#imag、Complex#r...

絞り込み条件を変える

<< 1 2 3 > >>