diff options
| author | William Hergès <william@herges.fr> | 2025-11-09 13:50:47 +0100 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-11-09 13:51:43 +0100 |
| commit | 27518174df347d1ee463cbe081c78f055e1af8d0 (patch) | |
| tree | 55b69bc1aeaa6bbb74658811d5a631f3c15eacd6 /lib/elixir_math_parser.ex | |
| parent | 7ddc83f098cfd316656c28dcca5375b939fd6c00 (diff) | |
style(calc): smaller expo
Diffstat (limited to 'lib/elixir_math_parser.ex')
| -rw-r--r-- | lib/elixir_math_parser.ex | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/elixir_math_parser.ex b/lib/elixir_math_parser.ex index b5e99bd..4d48065 100644 --- a/lib/elixir_math_parser.ex +++ b/lib/elixir_math_parser.ex @@ -68,19 +68,13 @@ defmodule ElixirMathParser do end end - # Functions for maths + # Functions for maths defp factor(n, acc) when n > 0, do: factor(n - 1, acc * n) defp factor(0, acc), do: acc - defp expo(value, exponent, acc) when exponent != 0 do - if exponent > 0 do - expo(value, exponent - 1, acc * value) - else - expo(value, exponent + 1, acc / value) - end - end - + defp expo(value, exponent, acc) when exponent > 0, do: expo(value, exponent - 1, acc * value) + defp expo(value, exponent, acc) when exponent < 0, do: expo(value, exponent + 1, acc / value) defp expo(_value, 0, acc), do: acc defp evaluate_tree([{:assign, {:var, line, lhs}, rhs} | tail], state) do |
