From 27518174df347d1ee463cbe081c78f055e1af8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sun, 9 Nov 2025 13:50:47 +0100 Subject: style(calc): smaller expo --- lib/elixir_math_parser.ex | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3