るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

キーワード

検索結果

<< < 1 2 3 > >>

Integer#div(other) -> Integer (37.0)

整商(整数の商)を返します。 普通の商(剰余を考えない商)を越えない最大の整数をもって整商とします。

...の場合、Integer#/ の結果と一致します。

div に対応する剰余メソッドは modulo です。

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

//emlist[例][ruby]{
7.div(2) # => 3
7.div(-2) # => -4
7.div(2.0) # => 3
7.div(Rational(2, 1)) # => 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...

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

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

...す。

@
param other self を割る数。

//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 Inte...
...ger#divmod, Integer#modulo, Numeric#modulo...

Numeric#divmod(other) -> [Numeric] (31.0)

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

...Numeric#div と同じです。
また余りは、Numeric#modulo と同じです。
このメソッドは、メソッド / と % によって定義されています。

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

//emlist[例][ruby]{
11.divmod(3) #=> [3, 2]
(11.5).divmod(3.5) #=...
...> [3, 1.0]
11.divmod(-3) #=> [-4, -1]
11.divmod(3.5) #=> [3, 0.5]
(-11).divmod(3.5) #=> [-4, 3.0]
//}

@
see Numeric#div, Numeric#modulo...

Float#divmod(other) -> [Numeric] (25.0)

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

...ます。

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

//emlist[例][ruby]{
11.divmod(3) # => [3, 2]
(11.5).divmod(3.5) # => [3, 1.0]
11.divmod(-3) # => [-4, -1]
11.divmod(3.5) # => [3, 0.5]
(-11).divmod(3.5) # => [-4, 3.0]
//}

@
see Numeric#div, Numeric#modulo...

Numeric#remainder(other) -> Numeric (25.0)

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

...します。

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

//emlist[例][ruby]{
p 13.remainder(4) #=> 1
p (11.5).remainder(3.5) #=> 1.0
p 13.remainder(-4) #=> 1
p (-13).remainder(4) #=> -1
p (-13).remainder(-4) #=> -1
p (-11).remainder(3.5) #=> -0.5
//}

@
see Numeric#divm...
...od, Numeric#modulo...

絞り込み条件を変える

Integer#%(other) -> Numeric (20.0)

算術演算子。剰余を計算します。

...算術演算子。剰余を計算します。

//emlist[][ruby]{
13 % 4 # => 1
13 % -4 # => -3
-13 % 4 # => 3
-13 % -4 # => -1
//}

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

Numeric#div(other) -> Integer (19.0)

self を other で割った整数の商 q を返します。

...りは Numeric#modulo で求められます。
div はメソッド / を呼びだし、floorを取ることで計算されます。

メソッド / の定義はサブクラスごとの定義を用います。

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

//emlist[例][ruby]{
p 3.div(2) # =>...

BigDecimal#%(n) -> BigDecimal (14.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 と同じ符号にな...

Float#%(other) -> Float (14.0)

算術演算子。剰余を計算します。

...算術演算子。剰余を計算します。

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

//emlist[例][ruby]{
# 剰余
3.0 % 1.2 # => 0.6000000000000001
3.0 % 0.0 # ZeroDivisionError
//}...
<< < 1 2 3 > >>