4 # real? -> true or false
6 # Returns +true+ if +self+ is a real number (i.e. not Complex).
22 # integer? -> true or false
24 # Returns +true+ if +self+ is an Integer.
26 # 1.0.integer? # => false
27 # 1.integer? # => true
34 # finite? -> true or false
36 # Returns +true+ if +self+ is a finite number, +false+ otherwise.
43 # infinite? -> -1, 1, or nil
45 # Returns +nil+, -1, or 1 depending on whether +self+ is
46 # finite, <tt>-Infinity</tt>, or <tt>+Infinity</tt>.
79 # Returns +self+, negated.
82 Primitive.cexpr! 'rb_int_uminus(self)'
89 # returns the value of +self+ with each bit inverted.
91 # Because an integer value is conceptually of infinite length,
92 # the result acts as if it had an infinite number of
93 # one bits to the left.
94 # In hex representations, this is displayed
95 # as two periods to the left of the digits:
97 # sprintf("%X", ~0x1122334455) # => "..FEEDDCCBBAA"
100 Primitive.attr! :leaf
101 Primitive.cexpr! 'rb_int_comp(self)'
107 # Returns the absolute value of +self+.
109 # (-12345).abs # => 12345
110 # -12345.abs # => 12345
111 # 12345.abs # => 12345
114 Primitive.attr! :leaf
115 Primitive.cexpr! 'rb_int_abs(self)'
119 # bit_length -> integer
121 # Returns the number of bits of the value of +self+,
122 # which is the bit position of the highest-order bit
123 # that is different from the sign bit
124 # (where the least significant bit has bit position 1).
125 # If there is no such bit (zero or minus one), returns zero.
127 # This method returns <tt>ceil(log2(self < 0 ? -self : self + 1))</tt>>.
129 # (-2**1000-1).bit_length # => 1001
130 # (-2**1000).bit_length # => 1000
131 # (-2**1000+1).bit_length # => 1000
132 # (-2**12-1).bit_length # => 13
133 # (-2**12).bit_length # => 12
134 # (-2**12+1).bit_length # => 12
135 # -0x101.bit_length # => 9
136 # -0x100.bit_length # => 8
137 # -0xff.bit_length # => 8
138 # -2.bit_length # => 1
139 # -1.bit_length # => 0
140 # 0.bit_length # => 0
141 # 1.bit_length # => 1
142 # 0xff.bit_length # => 8
143 # 0x100.bit_length # => 9
144 # (2**12-1).bit_length # => 12
145 # (2**12).bit_length # => 13
146 # (2**12+1).bit_length # => 13
147 # (2**1000-1).bit_length # => 1000
148 # (2**1000).bit_length # => 1001
149 # (2**1000+1).bit_length # => 1001
152 # this method can be used to detect overflow in Array#pack:
154 # if n.bit_length < 32
155 # [n].pack('l') # No overflow.
161 Primitive.attr! :leaf
162 Primitive.cexpr! 'rb_int_bit_length(self)'
166 # even? -> true or false
168 # Returns +true+ if +self+ is an even number, +false+ otherwise.
170 Primitive.attr! :leaf
171 Primitive.cexpr! 'rb_int_even_p(self)'
177 # Since +self+ is already an \Integer, always returns +true+.
185 # odd? -> true or false
187 # Returns +true+ if +self+ is an odd number, +false+ otherwise.
189 Primitive.attr! :leaf
190 Primitive.cexpr! 'rb_int_odd_p(self)'
197 # intended for compatibility to character literals in Ruby 1.9.
205 # Returns the number of bytes in the machine representation of +self+;
206 # the value is system-dependent:
210 # 2147483647.size # => 8
211 # (256**10 - 1).size # => 10
212 # (256**20 - 1).size # => 20
213 # (256**40 - 1).size # => 40
216 Primitive.attr! :leaf
217 Primitive.cexpr! 'rb_int_size(self)'
221 # times {|i| ... } -> self
222 # times -> enumerator
224 # Calls the given block +self+ times with each integer in <tt>(0..self-1)</tt>:
227 # 5.times {|i| a.push(i) } # => 5
228 # a # => [0, 1, 2, 3, 4]
230 # With no block given, returns an Enumerator.
232 Primitive.attr! :inline_block
233 unless defined?(yield)
234 return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, int_dotimes_size)'
247 # Returns +self+ (which is already an \Integer).
255 # Returns +self+ (which is already an \Integer).
261 # zero? -> true or false
263 # Returns +true+ if +self+ has a zero value, +false+ otherwise.
265 Primitive.attr! :leaf
266 Primitive.cexpr! 'rb_int_zero_p(self)'
270 # ceildiv(numeric) -> integer
272 # Returns the result of division +self+ by +numeric+.
273 # rounded up to the nearest integer.
275 # 3.ceildiv(3) # => 1
276 # 4.ceildiv(3) # => 2
278 # 4.ceildiv(-3) # => -1
279 # -4.ceildiv(3) # => -1
280 # -4.ceildiv(-3) # => 2
282 # 3.ceildiv(1.2) # => 3
312 # Returns +self+ (which is already a \Float).
320 # Returns the absolute value of +self+:
322 # (-34.56).abs # => 34.56
323 # -34.56.abs # => 34.56
324 # 34.56.abs # => 34.56
327 Primitive.attr! :leaf
328 Primitive.cexpr! 'rb_float_abs(self)'
332 Primitive.attr! :leaf
333 Primitive.cexpr! 'rb_float_abs(self)'
339 # Returns +self+, negated.
342 Primitive.attr! :leaf
343 Primitive.cexpr! 'rb_float_uminus(self)'
347 # zero? -> true or false
349 # Returns +true+ if +self+ is 0.0, +false+ otherwise.
351 Primitive.attr! :leaf
352 Primitive.cexpr! 'RBOOL(FLOAT_ZERO_P(self))'
356 # positive? -> true or false
358 # Returns +true+ if +self+ is greater than 0, +false+ otherwise.
360 Primitive.attr! :leaf
361 Primitive.cexpr! 'RBOOL(RFLOAT_VALUE(self) > 0.0)'
365 # negative? -> true or false
367 # Returns +true+ if +self+ is less than 0, +false+ otherwise.
369 Primitive.attr! :leaf
370 Primitive.cexpr! 'RBOOL(RFLOAT_VALUE(self) < 0.0)'