Returns true
if any bits of int & mask
are 1.
Returns true
if no bits of int & mask
are 1.
Returns the absolute value of int
.
(-12345).abs #=> 12345 -12345.abs #=> 12345 12345.abs #=> 12345
Integer#magnitude
is an alias for Integer#abs
.
Returns the digits of int
‘s place-value representation with radix base
(default: 10). The digits are returned as an array with the least significant digit as the first array element.
base
must be greater than or equal to 2.
12345.digits #=> [5, 4, 3, 2, 1] 12345.digits(7) #=> [4, 6, 6, 0, 5] 12345.digits(100) #=> [45, 23, 1] -12345.digits(7) #=> Math::DomainError
Returns a complex object which denotes the given rectangular form.
Complex.rectangular(1, 2) #=> (1+2i)
Returns a complex object which denotes the given polar form.
Complex.polar(3, 0) #=> (3.0+0.0i) Complex.polar(3, Math::PI/2) #=> (1.836909530733566e-16+3.0i) Complex.polar(3, Math::PI) #=> (-3.0+3.673819061467132e-16i) Complex.polar(3, -Math::PI/2) #=> (1.836909530733566e-16-3.0i)
Returns the imaginary part.
Complex(7).imaginary #=> 0 Complex(9, -4).imaginary #=> -4
Returns the absolute part of its polar form.
Complex(-1).abs #=> 1 Complex(3.0, -4.0).abs #=> 5.0
Returns the angle part of its polar form.
Complex.polar(3, Math::PI/2).arg #=> 1.5707963267948966
Returns an array; [cmp.abs, cmp.arg].
Complex(1, 2).polar #=> [2.23606797749979, 1.1071487177940904]
Returns true
if cmp
‘s real and imaginary parts are both finite numbers, otherwise returns false
.
Returns 1
if cmp
‘s real or imaginary part is an infinite number, otherwise returns nil
.
For example: (1+1i).infinite? #=> nil (Float::INFINITY + 1i).infinite? #=> 1
Returns zero.
Returns 0 if the value is positive, pi otherwise.
Returns an array; [num, 0].
Returns an array; [num.abs, num.arg].
Returns self.
Returns self.
Returns the receiver. freeze
cannot be false
.
Returns the absolute value of num
.
12.abs #=> 12 (-34.56).abs #=> 34.56 -34.56.abs #=> 34.56
Numeric#magnitude
is an alias for Numeric#abs
.
Returns self
if num
is not zero, nil
otherwise.
This behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A ) b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b } b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
Returns true
if num
is a finite number, otherwise returns false
.