るりまサーチ

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

別のキーワード

  1. openssl integer
  2. asn1 integer
  3. _builtin integer
  4. integer times
  5. integer upto

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Numeric (38212.0)

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

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

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

効率のため Numeric のメソッドと同じメソッドがサブクラスで再定義されている場合があります。

Numeric
#coerce メソッドを使うことによって異なる数値クラス間で演算を...

Numeric#integer? -> bool (27141.0)

自身が Integer かそのサブクラスのインスタンスの場合にtrue を返し ます。そうでない場合に false を返します。

...自身が Integer かそのサブクラスのインスタンスの場合にtrue を返し
ます。そうでない場合に false を返します。

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

//emlist[例][ruby]{
(1.0).integer? #=> fal...
...se
(1).integer? #=> true
//}

@see Numeric#real?...

Integer#divmod(other) -> [Integer, Numeric] (21208.0)

self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。

...self を other で割った商 q と余り r を、 [q, r] という 2 要素の配列にし
て返します。 商 q は常に整数ですが、余り r は整数であるとは限りません。

@param other self を割る数。

@see Numeric#divmod...

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

除算の算術演算子。

...除算の算術演算子。

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

other が Float、Rational、Complex の場合、普通の商を other と
...
...側の引数(対象)
@return 計算結果

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

begin
2 / 0
rescue => e
e # => #<ZeroDivisionError: divided by 0>
end
//}

@see Integer#div, Integer#fdiv, Numeric#quo...

Numeric#floor(ndigits = 0) -> Integer | Float (21131.0)

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

...Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。

//emlist[例][ruby]{
1.floor #=> 1
1.2.floor #=> 1
(-1.2).floor #=> -2
(-1.5).floor #=> -2
//}

@see Numeric#ceil, Numeric#round, Numeric#truncate
@see Integer#floor...

絞り込み条件を変える

Numeric#floor(ndigits = 0) -> Integer (21125.0)

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

...負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。

//emlist[例][ruby]{
1.floor #=> 1
1.2.floor #=> 1
(-1.2).floor #=> -2
(-1.5).floor #=> -2
//}

@see Numeric#ceil, Numeric#round, Numeric#truncate
@see Integer#floor...

Integer#fdiv(other) -> Numeric (21119.0)

self を other で割った商を Float で返します。 ただし Complex が関わる場合は例外です。 その場合も成分は Float になります。

...指定します。

例:

654321.fdiv(13731) # => 47.652829364212366
654321.fdiv(13731.24) # => 47.65199646936475

-1234567890987654321.fdiv(13731) # => -89910996357705.52
-1234567890987654321.fdiv(13731.24) # => -89909424858035.72
@see Numeric#quo, Numeric#div, Integer#div...

Integer#remainder(other) -> Numeric (21119.0)

self を other で割った余り r を返します。

.../emlist[][ruby]{
5.remainder(3) # => 2
-5.remainder(3) # => -2
5.remainder(-3) # => 2
-5.remainder(-3) # => -2

-1234567890987654321.remainder(13731) # => -6966
-1234567890987654321.remainder(13731.24) # => -9906.22531493148
//}

@see Integer#divmod, Integer#modulo, Numeric#modulo...

Integer#upto(max) {|n| ... } -> Integer (21119.0)

self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。

...self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。

@param max 数値
@return self を返します。

//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}

@see Integer#downto, Numeric#step, Integer#times...

Numeric#ceil -> Integer (21119.0)

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

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

//emlist[例][ruby]{
1.ceil #=> 1
1.2.ceil #=> 2
(-1.2).ceil #=> -1
(-1.5).ceil #=> -1
//}

@see Numeric#floor, Numeric#round, Numeric#truncate...

絞り込み条件を変える

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

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

...列にして返します。

デフォルトでは self と other を Float に変換して [other, self] という配列にして返します。
Numeric
のサブクラスは、このメソッドを適切に再定義しなければなりません。
以下は Rational の coerce のソースです...
...//emlist[例][ruby]{
# lib/rational.rb より

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

数値クラスの算術演算子は通常自分と演算できないク...
...んでいます。

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

def + (a)
if a.kind_of?(Rational)
# 長いので省略
elsif a.kind_of?(Integer)
# 長いので省略
elsif a.kind_of?(Float)
Float(self) + a
else
x, y = a.coerce(self)
x + y
end
end
//}

@param other...
<< 1 2 3 ... > >>