aboutsummaryrefslogtreecommitdiff
path: root/lib/math/Calc.ex
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 12:27:21 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-11-10 12:27:21 +0100
commit96299cbf09bdb75e4d6c6849c9c4c3ce000a6fc5 (patch)
tree7d5f21e6c884a2cd87c619c5d97fddb4cceb7ea8 /lib/math/Calc.ex
parent7536cdbd312dff03ab10e46929dc1b072f881d01 (diff)
feat(parser): supports literal decimal numbers
Diffstat (limited to 'lib/math/Calc.ex')
-rw-r--r--lib/math/Calc.ex28
1 files changed, 0 insertions, 28 deletions
diff --git a/lib/math/Calc.ex b/lib/math/Calc.ex
deleted file mode 100644
index 7dc5fcc..0000000
--- a/lib/math/Calc.ex
+++ /dev/null
@@ -1,28 +0,0 @@
-defmodule ElixirMathParser.Math.Calc do
- alias ElixirMathParser.Math.Rational
- def factorial(n), do: factorial_rec(n, 1)
- defp factorial_rec(n, acc) when n > 0, do: factorial_rec(n - 1, acc * n)
- defp factorial_rec(0, acc), do: acc
-
- def pow(value, exponent), do: pow_rec(value, exponent, Rational.new(1))
-
- defp pow_rec(value, exponent, acc) when is_integer(exponent) do
- case exponent do
- 0 ->
- acc
-
- _ when exponent < 0 ->
- pow_rec(Rational.new(1, value), -exponent, acc)
-
- _ when Kernel.rem(exponent, 2) == 0 ->
- pow_rec(Rational.mult(value, value), Kernel.div(exponent, 2), acc)
-
- _ ->
- pow_rec(
- Rational.mult(value, value),
- Kernel.div(exponent - 1, 2),
- Rational.mult(acc, value)
- )
- end
- end
-end