種類
- インスタンスメソッド (202)
- クラス (11)
- 文書 (11)
ライブラリ
- ビルトイン (191)
- bigdecimal (22)
検索結果
先頭5件
-
Numeric
# modulo(other) -> Numeric (15143.0) -
self を other で割った余り r を返します。
...ます。
modulo はメソッド % の呼び出しとして定義されています。
@param other 自身を割る数を指定します。
//emlist[例][ruby]{
p 13.modulo(4) #=> 1
p (11.5).modulo(3.5) #=> 1.0
p 13.modulo(-4) #=> -3
p (-13).modulo(4) #=> 3
p (-13).modulo(-4) #=>......-1
p (-11).modulo(3.5) #=> 3.0
//}
@see Numeric#divmod, Numeric#remainder... -
BigDecimal
# modulo(n) -> BigDecimal (15101.0) -
self を n で割った余りを返します。
self を n で割った余りを返します。
@param n self を割る数を指定します。
//emlist[][ruby]{
require 'bigdecimal'
x = BigDecimal((2**100).to_s)
( x % 3).to_i # => 1
(-x % 3).to_i # => 2
( x % -3).to_i # => -2
(-x % -3).to_i # => -1
//}
戻り値は n と同じ符号になります。これは BigDecimal#remainder とは
異なる点に注意してください。詳細は Numeric#%、
Numeric#re... -
Bignum
# modulo(other) -> Fixnum | Bignum | Float (15101.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
@return 計算結果 -
Fixnum
# modulo(other) -> Fixnum | Bignum | Float (15101.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
@return 計算結果 -
Float
# modulo(other) -> Float (15101.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 剰余
3.0 % 1.2 # => 0.6000000000000001
3.0 % 0.0 # ZeroDivisionError
//} -
Integer
# modulo(other) -> Numeric (15101.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}
@param other 二項演算の右側の引数(対象)
@return 計算結果 -
Integer
# pow(other , modulo) -> Integer (113.0) -
算術演算子。冪(べき乗)を計算します。
...子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外... -
Numeric
# %(other) -> Numeric (43.0) -
self を other で割った余り r を返します。
...ます。
modulo はメソッド % の呼び出しとして定義されています。
@param other 自身を割る数を指定します。
//emlist[例][ruby]{
p 13.modulo(4) #=> 1
p (11.5).modulo(3.5) #=> 1.0
p 13.modulo(-4) #=> -3
p (-13).modulo(4) #=> 3
p (-13).modulo(-4) #=>......-1
p (-11).modulo(3.5) #=> 3.0
//}
@see Numeric#divmod, Numeric#remainder... -
Integer
# **(other) -> Numeric (13.0) -
算術演算子。冪(べき乗)を計算します。
...子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外... -
Integer
# pow(other) -> Numeric (13.0) -
算術演算子。冪(べき乗)を計算します。
...子。冪(べき乗)を計算します。
@param other 二項演算の右側の引数(対象)
@param modulo 指定すると、計算途中に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外... -
Bignum
# remainder(other) -> Fixnum | Bignum | Float (12.0) -
self を other で割った余り r を返します。
...self を other で割った余り r を返します。
r の符号は self と同じになります。
@param other self を割る数。
@see Bignum#divmod, Bignum#modulo, Numeric#modulo... -
Integer
# div(other) -> Integer (12.0) -
整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。
...とします。
other が Integer オブジェクトの場合、Integer#/ の結果と一致します。
div に対応する剰余メソッドは modulo です。
@param other 二項演算の右側の引数(対象)
@return 計算結果
//emlist[例][ruby]{
7.div(2) # => 3
7.div(-2) # => -4
7.div......=> 3
begin
2.div(0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
end
begin
2.div(0.0)
rescue => e
e # => #<ZeroDivisionError: divided by 0>
# Integer#/ と違い、引数が Float でもゼロで割ることはできない
end
//}
@see Integer#fdiv, Integer#/, Integer#modulo...