parent
6586516511
commit
9bd4347abb
1 changed files with 21 additions and 16 deletions
|
|
@ -975,16 +975,21 @@ proc `^`*[T](x: T, y: Natural): T =
|
||||||
## * `sqrt proc <#sqrt,float64>`_
|
## * `sqrt proc <#sqrt,float64>`_
|
||||||
## * `cbrt proc <#cbrt,float64>`_
|
## * `cbrt proc <#cbrt,float64>`_
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
runnableExamples:
|
||||||
## echo 2^3 # 8
|
assert -3.0^0 == 1.0
|
||||||
## echo -2^3 # -8
|
assert -3^1 == -3
|
||||||
when compiles(y >= T(0)):
|
assert -3^2 == 9
|
||||||
assert y >= T(0)
|
assert -3.0^3 == -27.0
|
||||||
|
assert -3.0^4 == 81.0
|
||||||
|
|
||||||
|
case y
|
||||||
|
of 0: result = 1
|
||||||
|
of 1: result = x
|
||||||
|
of 2: result = x * x
|
||||||
|
of 3: result = x * x * x
|
||||||
else:
|
else:
|
||||||
assert T(y) >= T(0)
|
|
||||||
var (x, y) = (x, y)
|
var (x, y) = (x, y)
|
||||||
result = 1
|
result = 1
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if (y and 1) != 0:
|
if (y and 1) != 0:
|
||||||
result *= x
|
result *= x
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue