種類
- インスタンスメソッド (300)
- 特異メソッド (2)
ライブラリ
- ビルトイン (302)
キーワード
- % (3)
- & (3)
- * (3)
- ** (3)
- + (3)
- - (3)
- -@ (3)
-
/ (2) - < (3)
- << (3)
- <= (3)
- <=> (3)
- == (3)
- === (3)
- > (3)
- >= (3)
- >> (3)
- [] (3)
- ^ (3)
- abs (3)
- allbits? (2)
- anybits? (2)
-
bit
_ length (3) - ceil (6)
- chr (12)
- denominator (6)
- digits (6)
- div (3)
- divmod (3)
- downto (12)
- even? (6)
- fdiv (3)
- floor (6)
- gcd (6)
- gcdlcm (6)
- inspect (6)
- integer? (6)
- lcm (6)
- magnitude (3)
- modulo (3)
- next (6)
- nobits? (2)
- numerator (6)
- odd? (6)
- ord (6)
- pow (4)
- pred (6)
- rationalize (12)
- remainder (3)
- round (6)
- size (3)
- sqrt (2)
- succ (6)
- times (12)
-
to
_ f (3) -
to
_ i (6) -
to
_ int (6) -
to
_ r (6) -
to
_ s (12) - truncate (6)
- upto (12)
- | (3)
- ~ (3)
検索結果
先頭5件
-
Integer
# integer? -> true (23114.0) -
常に真を返します。
...常に真を返します。
例:
1.integer? # => true
1.0.integer? # => false... -
Integer
. sqrt(n) -> Integer (17150.0) -
非負整数 n の整数の平方根を返します。すなわち n の平方根以下の 最大の非負整数を返します。
...。Integer ではない場合は、最初に Integer に変換されます。
@raise Math::DomainError n が負の整数の時に発生します。
//emlist[][ruby]{
Integer.sqrt(0) # => 0
Integer.sqrt(1) # => 1
Integer.sqrt(24) # => 4
Integer.sqrt(25) # => 5
Integer.sqrt(......).floor と同等ですが、後者は浮動小数点数の精度の限界によって
真の値とは違う結果になることがあります。
//emlist[][ruby]{
Integer.sqrt(10**46) #=> 100000000000000000000000
Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
//}
@see Math.sqrt... -
Integer
# gcd(n) -> Integer (17114.0) -
自身と整数 n の最大公約数を返します。
...# => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
また、self や n が 0 だった場合は、0 ではない方の整数の絶対値を返します。
3.gcd(0) # => 3
0.gcd(-7) # => 7
@see Integer#lcm, Integer#gcdlcm... -
Integer
# gcdlcm(n) -> [Integer] (17114.0) -
自身と整数 n の最大公約数と最小公倍数の配列 [self.gcd(n), self.lcm(n)] を返します。
...します。
@raise ArgumentError n に整数以外のものを指定すると発生します。
例:
2.gcdlcm(2) # => [2, 2]
3.gcdlcm(-7) # => [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1) # => [1, 4951760154835678088235319297]
@see Integer#gcd, Integer#lcm... -
Integer
# lcm(n) -> Integer (17114.0) -
自身と整数 n の最小公倍数を返します。
...# => 2
3.lcm(-7) # => 21
((1<<31)-1).lcm((1<<61)-1) # => 4951760154835678088235319297
また、self や n が 0 だった場合は、0 を返します。
3.lcm(0) # => 0
0.lcm(-7) # => 0
@see Integer#gcd, Integer#gcdlcm... -
Integer
# upto(max) {|n| . . . } -> Integer (17114.0) -
self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。
...ん。
@param max 数値
@return self を返します。
例:
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
@see Integer#downto, Numeric#step, Integer#times... -
Integer
# next -> Integer (17109.0) -
self の次の整数を返します。
...self の次の整数を返します。
例:
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
@see Integer#pred... -
Integer
# succ -> Integer (17109.0) -
self の次の整数を返します。
...self の次の整数を返します。
例:
1.next #=> 2
(-1).next #=> 0
1.succ #=> 2
(-1).succ #=> 0
@see Integer#pred... -
Integer
# ceil(ndigits = 0) -> Integer | Float (17108.0) -
self と等しいかより大きな整数のうち最小のものを返します。
...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.ceil # =... -
Integer
# denominator -> Integer (17108.0) -
分母(常に1)を返します。
...分母(常に1)を返します。
@return 分母を返します。
例:
10.denominator # => 1
-10.denominator # => 1
@see Integer#numerator... -
Integer
# floor(ndigits = 0) -> Integer | Float (17108.0) -
self と等しいかより小さな整数のうち最大のものを返します。
...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.floor #... -
Integer
# numerator -> Integer (17108.0) -
分子(常に自身)を返します。
...分子(常に自身)を返します。
@return 分子を返します。
例:
10.numerator # => 10
-10.numerator # => -10
@see Integer#denominator... -
Integer
# pow(other , modulo) -> Integer (17108.0) -
算術演算子。冪(べき乗)を計算します。
...に巨大な値を生成せずに (self**other) % modulo と同じ結果を返します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。... -
Integer
# pred -> Integer (17108.0) -
self から -1 した値を返します。
...self から -1 した値を返します。
1.pred #=> 0
(-1).pred #=> -2
@see Integer#next... -
Integer
# round(ndigits = 0 , half: :up) -> Integer | Float (17108.0) -
self ともっとも近い整数を返します。
...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
@param half ちょうど半分の値の... -
Integer
# truncate(ndigits = 0) -> Integer | Float (17108.0) -
0 から self までの整数で、自身にもっとも近い整数を返します。
...合、Float を返します。
小数点以下を、最大 n 桁にします。
負の整数を指定した場合、Integer を返します。
小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.truncate... -
Integer
# abs -> Integer (17103.0) -
self の絶対値を返します。
self の絶対値を返します。
例:
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321 -
Integer
# digits -> [Integer] (17103.0) -
base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。
base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。
-10.digits # Math::DomainError: out of domain が発生
@return 位取り記数法で表した時の数値の配列
@param base 基数となる数値。
@raise ArgumentEr... -
Integer
# digits(base) -> [Integer] (17103.0) -
base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。
base を基数として self を位取り記数法で表記した数値を配列で返します。
base を指定しない場合の基数は 10 です。
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。
-10.digits # Math::DomainError: out of domain が発生
@return 位取り記数法で表した時の数値の配列
@param base 基数となる数値。
@raise ArgumentEr... -
Integer
# magnitude -> Integer (17103.0) -
self の絶対値を返します。
self の絶対値を返します。
例:
-12345.abs # => 12345
12345.abs # => 12345
-1234567890987654321.abs # => 1234567890987654321 -
Integer
# &(other) -> Integer (17102.0) -
ビット二項演算子。論理積を計算します。
ビット二項演算子。論理積を計算します。
@param other 数値
例:
1 & 1 # => 1
2 & 3 # => 2 -
Integer
# -@ -> Integer (17102.0) -
単項演算子の - です。 self の符号を反転させたものを返します。
単項演算子の - です。
self の符号を反転させたものを返します。
例:
- 10 # => -10
- -10 # => 10 -
Integer
# <<(bits) -> Integer (17102.0) -
シフト演算子。bits だけビットを左にシフトします。
シフト演算子。bits だけビットを左にシフトします。
@param bits シフトさせるビット数
例:
printf("%#b\n", 0b0101 << 1) # => 0b1010
p -1 << 1 # => -2 -
Integer
# >>(bits) -> Integer (17102.0) -
シフト演算子。bits だけビットを右にシフトします。
シフト演算子。bits だけビットを右にシフトします。
右シフトは、符号ビット(最上位ビット(MSB))が保持されます。
bitsが実数の場合、小数点以下を切り捨てた値でシフトします。
@param bits シフトさせるビット数
例:
printf("%#b\n", 0b0101 >> 1) # => 0b10
p -1 >> 1 # => -1 -
Integer
# [](nth) -> Integer (17102.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1
を、そうでなければ 0 を返します。
@param nth 何ビット目を指すかの数値
@return 1 か 0
self[nth]=bit (つまりビットの修正) がないのは、Numeric 関連クラスが
immutable であるためです。
例:
a = 0b11001100101010
30.downto(0) do |n| print a[n] end
# => 0000000000000000011001100101010
a = 9**15
50.downto(0... -
Integer
# ^(other) -> Integer (17102.0) -
ビット二項演算子。排他的論理和を計算します。
ビット二項演算子。排他的論理和を計算します。
@param other 数値
例:
1 ^ 1 # => 0
2 ^ 3 # => 1 -
Integer
# bit _ length -> Integer (17102.0) -
self を表すのに必要なビット数を返します。
self を表すのに必要なビット数を返します。
「必要なビット数」とは符号ビットを除く最上位ビットの位置の事を意味しま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果
(-2**12-1).bit_length # => 13
(-2**12).bit_length # => 12
(-2**12+1).bit_length # => 12
-0x101.bit_len... -
Integer
# ceil(ndigits = 0) -> Integer (17102.0) -
self と等しいかより大きな整数のうち最小のものを返します。
self と等しいかより大きな整数のうち最小のものを返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.ceil # => 1
1.ceil(2) # => 1
18.ceil(-1) # => 20
(-18).ceil(-1) # => -10
//}
@see Numeric#ceil -
Integer
# divmod(other) -> [Integer , Numeric] (17102.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
# floor(ndigits = 0) -> Integer (17102.0) -
self と等しいかより小さな整数のうち最大のものを返します。
self と等しいかより小さな整数のうち最大のものを返します。
@param ndigits 10進数での小数点以下の有効桁数を整数で指定します。
負の整数を指定した場合、小数点位置から左に少なくとも n 個の 0 が並びます。
//emlist[][ruby]{
1.floor # => 1
1.floor(2) # => 1
18.floor(-1) # => 10
(-18).floor(-1) # => -20
//}
@see Numeric#floor -
Integer
# ord -> Integer (17102.0) -
自身を返します。
自身を返します。
10.ord #=> 10
# String#ord
?a.ord #=> 97
@see String#ord