mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
[DOC] Tweaks for Integer#**
This commit is contained in:
parent
b47b37c12c
commit
7789aaca37
Notes:
git
2025-11-21 22:17:01 +00:00
49
numeric.c
49
numeric.c
@ -4592,17 +4592,48 @@ fix_pow(VALUE x, VALUE y)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* self ** numeric -> numeric_result
|
||||
* self ** exponent -> numeric
|
||||
*
|
||||
* Raises +self+ to the power of +numeric+:
|
||||
* Returns the value of base +self+ raised to the power +exponent+;
|
||||
* see {Exponentiation}[https://en.wikipedia.org/wiki/Exponentiation]:
|
||||
*
|
||||
* 2 ** 3 # => 8
|
||||
* 2 ** -3 # => (1/8)
|
||||
* -2 ** 3 # => -8
|
||||
* -2 ** -3 # => (-1/8)
|
||||
* 2 ** 3.3 # => 9.849155306759329
|
||||
* 2 ** Rational(3, 1) # => (8/1)
|
||||
* 2 ** Complex(3, 0) # => (8+0i)
|
||||
* # Result for non-negative Integer exponent is Integer.
|
||||
* 2 ** 0 # => 1
|
||||
* 2 ** 1 # => 2
|
||||
* 2 ** 2 # => 4
|
||||
* 2 ** 3 # => 8
|
||||
* -2 ** 3 # => -8
|
||||
* # Result for negative Integer exponent is Rational, not Float.
|
||||
* 2 ** -3 # => (1/8)
|
||||
* -2 ** -3 # => (-1/8)
|
||||
*
|
||||
* # Result for Float exponent is Float.
|
||||
* 2 ** 0.0 # => 1.0
|
||||
* 2 ** 1.0 # => 2.0
|
||||
* 2 ** 2.0 # => 4.0
|
||||
* 2 ** 3.0 # => 8.0
|
||||
* -2 ** 3.0 # => -8.0
|
||||
* 2 ** -3.0 # => 0.125
|
||||
* -2 ** -3.0 # => -0.125
|
||||
*
|
||||
* # Result for non-negative Complex exponent is Complex with Integer parts.
|
||||
* 2 ** Complex(0, 0) # => (1+0i)
|
||||
* 2 ** Complex(1, 0) # => (2+0i)
|
||||
* 2 ** Complex(2, 0) # => (4+0i)
|
||||
* 2 ** Complex(3, 0) # => (8+0i)
|
||||
* -2 ** Complex(3, 0) # => (-8+0i)
|
||||
* # Result for negative Complex exponent is Complex with Rational parts.
|
||||
* 2 ** Complex(-3, 0) # => ((1/8)+(0/1)*i)
|
||||
* -2 ** Complex(-3, 0) # => ((-1/8)+(0/1)*i)
|
||||
*
|
||||
* # Result for Rational exponent is Rational.
|
||||
* 2 ** Rational(0, 1) # => (1/1)
|
||||
* 2 ** Rational(1, 1) # => (2/1)
|
||||
* 2 ** Rational(2, 1) # => (4/1)
|
||||
* 2 ** Rational(3, 1) # => (8/1)
|
||||
* -2 ** Rational(3, 1) # => (-8/1)
|
||||
* 2 ** Rational(-3, 1) # => (1/8)
|
||||
* -2 ** Rational(-3, 1) # => (-1/8)
|
||||
*
|
||||
*/
|
||||
VALUE
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user