るりまサーチ

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

別のキーワード

  1. _builtin *
  2. matrix *
  3. array *
  4. vector *
  5. bigdecimal *

キーワード

検索結果

Integer#*(other) -> Numeric (18109.0)

算術演算子。積を計算します。

...算術演算子。積を計算します。

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

//emlist[][ruby]{
2 * 3 # => 6
//}...

Integer#**(other) -> Numeric (6103.0)

算術演算子。冪(べき乗)を計算します。

...elf**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0...
...# => 1
0 ** 0 # => 1
3.pow(3, 8) # => 3
3.pow(3, -8) # => -5
3.pow(2, -2) # => -1
-3.pow(3, 8) # => 5
-3.pow(3, -8) # => -3
5.pow(2, -8) # => -7
//}

結果が巨大すぎる整数になりそうなとき、警告を出したうえで Float::INFINITY を返します。

//emlist[計算を...
...放棄して Float::INFINITY を返す例][ruby]{
p 100**9999999
# => warning: in a**b, b may be too big
# Infinity
//}

判定の閾値は変わりえます。

@see BigDecimal#power...

Integer#pow(other) -> Numeric (3003.0)

算術演算子。冪(べき乗)を計算します。

...elf**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0...
...# => 1
0 ** 0 # => 1
3.pow(3, 8) # => 3
3.pow(3, -8) # => -5
3.pow(2, -2) # => -1
-3.pow(3, 8) # => 5
-3.pow(3, -8) # => -3
5.pow(2, -8) # => -7
//}

結果が巨大すぎる整数になりそうなとき、警告を出したうえで Float::INFINITY を返します。

//emlist[計算を...
...放棄して Float::INFINITY を返す例][ruby]{
p 100**9999999
# => warning: in a**b, b may be too big
# Infinity
//}

判定の閾値は変わりえます。

@see BigDecimal#power...

Integer#pow(other, modulo) -> Integer (3003.0)

算術演算子。冪(べき乗)を計算します。

...elf**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0...
...# => 1
0 ** 0 # => 1
3.pow(3, 8) # => 3
3.pow(3, -8) # => -5
3.pow(2, -2) # => -1
-3.pow(3, 8) # => 5
-3.pow(3, -8) # => -3
5.pow(2, -8) # => -7
//}

結果が巨大すぎる整数になりそうなとき、警告を出したうえで Float::INFINITY を返します。

//emlist[計算を...
...放棄して Float::INFINITY を返す例][ruby]{
p 100**9999999
# => warning: in a**b, b may be too big
# Infinity
//}

判定の閾値は変わりえます。

@see BigDecimal#power...

Integer#round(ndigits = 0, half: :up) -> Integer (21.0)

self ともっとも近い整数を返します。

...方を指定します。
サポートされている値は以下の通りです。

*
:up or nil: 0から遠い方に丸められます。
*
:even: もっとも近い偶数に丸められます。
*
:down: 0に近い方に丸められます。

//emlist[][ruby]{
1.round # => 1
1.ro...

絞り込み条件を変える

Integer#round(ndigits = 0, half: :up) -> Integer | Float (21.0)

self ともっとも近い整数を返します。

...を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の値の丸め方を指定します。
サポートされている値は以下の通りです。

*
:up or nil: 0から遠...
...い方に丸められます。
*
:even: もっとも近い偶数に丸められます。
*
:down: 0に近い方に丸められます。

//emlist[][ruby]{
1.round # => 1
1.round(2) # => 1.0
15.round(-1) # => 20
(-15).round(-1) # => -20

25.round(-1, half: :up) # => 30
25.roun...

Integer#to_f -> Float (15.0)

self を浮動小数点数(Float)に変換します。

...self を浮動小数点数(Float)に変換します。

self が Float の範囲に収まらない場合、Float::INFINITY を返します。

//emlist[][ruby]{
1.to_f # => 1.0
(Float::MAX.to_i * 2).to_f # => Infinity
(-Float::MAX.to_i * 2).to_f # => -Infinity
//}...