September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,19 +0,0 @@
|
|||
% -spec attribute is for documentation and dialyzer static analysis purposes only.
|
||||
% It does not constrain the function like a guard (when ... ).
|
||||
-spec exp_int(X :: integer(), N :: non_neg_integer()) -> integer().
|
||||
|
||||
% X ^ 0
|
||||
exp_int(X, 0) when is_integer(X) -> % is_integer guard is required, otherwise X would match anything.
|
||||
1;
|
||||
|
||||
% X ^ odd
|
||||
exp_int(X, N) when is_integer(X), N >= 1, N rem 2 == 1 ->
|
||||
Part = exp_int(X, (N-1) div 2),
|
||||
X * Part * Part;
|
||||
|
||||
% X ^ even
|
||||
exp_int(X, N) when is_integer(X), N >= 2, N rem 2 == 0 ->
|
||||
Part = exp_int(X, N div 2),
|
||||
Part * Part.
|
||||
|
||||
% X ^ negative is excluded because it would return float.
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
% -spec attribute is for documentation and dialyzer static analysis purposes only.
|
||||
% It does not constrain the function like a guard (when ... ).
|
||||
-spec exp_float(X :: float(), N :: integer()) -> float().
|
||||
|
||||
% X ^ 0
|
||||
exp_float(X, 0) when is_float(X) -> % is_float guard is required, otherwise X would match anything.
|
||||
1.0;
|
||||
|
||||
% X ^ negative
|
||||
exp_float(X, N) when is_float(X), N < 0 ->
|
||||
1.0 / exp_float(X, -N);
|
||||
|
||||
% X ^ even
|
||||
exp_float(X, N) when is_float(X), N >= 1, N rem 2 == 1 ->
|
||||
Part = exp_float(X, (N-1) div 2),
|
||||
X * Part * Part;
|
||||
|
||||
% X ^ odd
|
||||
exp_float(X, N) when is_float(X), N >= 2, N rem 2 == 0 ->
|
||||
Part = exp_float(X, N div 2),
|
||||
Part * Part.
|
||||
Loading…
Add table
Add a link
Reference in a new issue