Returns zero as a complex.
Always returns the empty string.
Returns zero as a rational.
Returns the value as a complex.
Returns self.
Returns an array; [num, 0].
Returns an array; [num, 0].
Returns true
if num
is a Real number. (i.e. not Complex
).
Returns the largest integer less than or equal to num
.
Numeric
implements this by converting an Integer
to a Float
and invoking Float#floor
.
1.floor #=> 1 (-1).floor #=> -1
Invokes the given block with the sequence of numbers starting at num
, incremented by step
(defaulted to 1
) on each call.
The loop finishes when the value to be passed to the block is greater than limit
(if step
is positive) or less than limit
(if step
is negative), where limit is defaulted to infinity.
In the recommended keyword argument style, either or both of step
and limit
(default infinity) can be omitted. In the fixed position argument style, zero as a step (i.e. num.step(limit, 0)) is not allowed for historical compatibility reasons.
If all the arguments are integers, the loop operates using an integer counter.
If any of the arguments are floating point numbers, all are converted to floats, and the loop is executed the following expression:
floor(n + n*epsilon)+ 1
Where the n
is the following:
n = (limit - num)/step
Otherwise, the loop starts at num
, uses either the less-than (<) or greater-than (>) operator to compare the counter against limit
, and increments itself using the +
operator.
If no block is given, an Enumerator
is returned instead.
For example:
p 1.step.take(4) p 10.step(by: -1).take(4) 3.step(to: 5) { |i| print i, " " } 1.step(10, 2) { |i| print i, " " } Math::E.step(to: Math::PI, by: 0.2) { |f| print f, " " }
Will produce:
[1, 2, 3, 4] [10, 9, 8, 7] 3 4 5 1 3 5 7 9 2.71828182845905 2.91828182845905 3.11828182845905
Returns a complex which denotes the string form. The parser ignores leading whitespaces and trailing garbage. Any digit sequences can be separated by an underscore. Returns zero for null or garbage string.
'9'.to_c #=> (9+0i) '2.5'.to_c #=> (2.5+0i) '2.5/1'.to_c #=> ((5/2)+0i) '-3/2'.to_c #=> ((-3/2)+0i) '-i'.to_c #=> (0-1i) '45i'.to_c #=> (0+45i) '3-4i'.to_c #=> (3-4i) '-4e2-4e-2i'.to_c #=> (-400.0-0.04i) '-0.0-0.0i'.to_c #=> (-0.0-0.0i) '1/2+3/4i'.to_c #=> ((1/2)+(3/4)*i) 'ruby'.to_c #=> (0+0i)
See Kernel.Complex
.
Returns the result of interpreting leading characters in str
as a BigDecimal
.
require 'bigdecimal' require 'bigdecimal/util' "0.5".to_d # => 0.5e0 "123.45e1".to_d # => 0.12345e4 "45.67 degrees".to_d # => 0.4567e2
See also BigDecimal::new
.
Convert self
to ISO-2022-JP
Convert self
to EUC-JP
Convert self
to Shift_JIS
Convert self
to UTF-8
Convert self
to UTF-16
Convert self
to UTF-32
Convert self
to locale encoding