クラス
- Bignum (3)
- CSV (11)
- Fixnum (3)
- Float (33)
- Integer (263)
- Numeric (216)
-
OpenSSL
:: BN (11) - OptionParser (132)
- Range (11)
- Socket (44)
- Time (47)
- UnboundMethod (11)
モジュール
- GC (22)
- Kernel (22)
- Math (4)
-
OpenSSL
:: ASN1 (11) -
Socket
:: Constants (44)
キーワード
- % (11)
- * (11)
- ** (11)
- + (11)
- - (11)
- -@ (11)
-
/ (11) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) -
AI
_ NUMERICHOST (22) -
AI
_ NUMERICSERV (22) - Converters (11)
-
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 4 . 0 (8) -
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 6 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (4) -
NI
_ NUMERICHOST (22) -
NI
_ NUMERICSERV (22) - NUMERICSTRING (11)
- Ruby用語集 (11)
- [] (21)
- at (47)
- bigdecimal (11)
- ceil (22)
-
check
_ signedness (22) - coerce (22)
- denominator (11)
- div (11)
- divmod (17)
- downto (22)
- fdiv (11)
- floor (33)
- integer? (11)
- matrix (11)
- modulo (11)
- numerator (11)
- on (132)
- owner (11)
- pow (22)
- real? (11)
- remainder (11)
- round (22)
- rsqrt (4)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 4 feature (11) - size (11)
- stat (22)
- step (84)
- times (22)
-
to
_ i (11) -
to
_ int (11) - truncate (33)
- upto (22)
検索結果
先頭5件
-
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...