るりまサーチ

最速Rubyリファレンスマニュアル検索!
722件ヒット [201-300件を表示] (0.082秒)
トップページ > クエリ:Ruby[x] > クエリ:ruby[x] > 種類:インスタンスメソッド[x] > クエリ:-[x] > クエリ:@[x] > クラス:Integer[x]

別のキーワード

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

ライブラリ

キーワード

検索結果

<< < 1 2 3 4 5 ... > >>

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

除算の算術演算子。

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

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

other が Float、Rational、Complex の場合、普通の商を other と
...
...

@
param 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#d...
...iv, Integer#fdiv, Numeric#quo...

Integer#inspect(base=10) -> String (144.0)

整数を 10 進文字列表現に変換します。

...変換します。

//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}

@
return 数値の文字列表現
@
param base 基数となる 2 - 36 の数値。
@
raise ArgumentError base に 2 - 36 以外の数値を指定した...

Integer#to_s(base=10) -> String (144.0)

整数を 10 進文字列表現に変換します。

...変換します。

//emlist[][ruby]{
p 10.to_s(2) # => "1010"
p 10.to_s(8) # => "12"
p 10.to_s(16) # => "a"
p 35.to_s(36) # => "z"
//}

@
return 数値の文字列表現
@
param base 基数となる 2 - 36 の数値。
@
raise ArgumentError base に 2 - 36 以外の数値を指定した...

Integer#pred -> Integer (142.0)

self から -1 した値を返します。

...self から -1 した値を返します。

//emlist[][ruby]{
1.pred #=> 0
(-1).pred #=> -2
//}

@
see Integer#next...

Integer#[](nth) -> Integer (138.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

...下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。

@
param nth 何ビット目を指すかの数値
@
return 1 か 0

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.d...
...00011110010100111100010111001
//}

n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。

//emlist[][ruby]{
p 255[-1] # => 0
//}


self[nth]=bit (つまりビットの修正) がないのは、Numeric 関連クラスが
immutable であるためです。...

絞り込み条件を変える

Integer#ceildiv(other) -> Integer (138.0)

self を other で割り、その(剰余を考えない)商を整数に切り上げたものを返します。 すなわち、self を other で割った商を q とすると、q 以上で最小の整数を返します。

...r で割った商を q とすると、q 以上で最小の整数を返します。

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

//emlist[][ruby]{
3.ceildiv(3) # => 1
4.ceildiv(3) # => 2
5.ceildiv(3) # => 2
3.ceildiv(1.2) # => 3
-
5.ceildiv(3) # => -1
-
5.ceildiv(-3) # => 2
//}...

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

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

...す。

other が Integer オブジェクトの場合、Integer#/ の結果と一致します。

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

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

//emlist[例][ruby]{
7.div(2) # => 3
7.div(-2) # => -4
7.div(2.0) # =...
...=> 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#gcd(n) -> Integer (138.0)

自身と整数 n の最大公約数を返します。

...最大公約数を返します。

@
raise ArgumentError n に整数以外のものを指定すると発生します。

//emlist[][ruby]{
2.gcd(2) # => 2
3.gcd(7) # => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
//}

また、self や...
...n が 0 だった場合は、0 ではない方の整数の絶対値を返します。

//emlist[][ruby]{
3.gcd(0) # => 3
0.gcd(-7) # => 7
//}

@
see Integer#lcm, Integer#gcdlcm...

Integer#lcm(n) -> Integer (138.0)

自身と整数 n の最小公倍数を返します。

...と整数 n の最小公倍数を返します。

@
raise ArgumentError n に整数以外のものを指定すると発生します。

//emlist[][ruby]{
2.lcm(2) # => 2
3.lcm(-7) # => 21
((1<<31)-1).lcm((1<<61)-1) # => 4951760154835678088235319297
//}

また、...
...self や n が 0 だった場合は、0 を返します。

//emlist[][ruby]{
3.lcm(0) # => 0
0.lcm(-7) # => 0
//}

@
see Integer#gcd, Integer#gcdlcm...

Integer#numerator -> Integer (138.0)

分子(常に自身)を返します。

...分子(常に自身)を返します。

@
return 分子を返します。

//emlist[][ruby]{
10.numerator # => 10
-
10.numerator # => -10
//}

@
see Integer#denominator...

絞り込み条件を変える

<< < 1 2 3 4 5 ... > >>