README.md
1# Math
2
3The Math module adds many useful functions that extend Elixir's standard library.
4
5- General Functions
6 - `a <~> b` Comparison of floats, to check if they are _nearly_ equal.
7 - `Math.pow(x, n)` Arithmetic exponentiation. Works both with integer powers and floats.
8 - `Math.sqrt(x)` The square root of *x*.
9 - `Math.nth_root(x, n)` The n-th root of *x*.
10 - `Math.isqrt(x)` The integer square root of *x*.
11 - `Math.gcd(a, b)` The greatest common divisor of *a* and *b*.
12 - `Math.lcm(a, b)` The least common multiple of *a* and *b*.
13 - `Math.factorial(n)` The *n*-th factorial number.
14 - `Math.k_permutations(n, k)` The number of distinct ways to create groups of size *k* from *n* distinct elements.
15 - `Math.k_combinations(n, k)` The number of distinct ways to create groups of size *k* from *n* distinct elements where order does not matter.
16
17
18- Logarithms
19 - `Math.exp(x)` Calculates ℯ to the xth power.
20 - `Math.log(x)` Calculates the natural logarithm (base `ℯ`) of *x*.
21 - `Math.log(x, b)` Calculates the base-*b* logarithm of *x*
22 - `Math.log2(x)` Calculates the binary logarithm (base `2`) of *x*.
23 - `Math.log10(x)` Calculates the common logarithm (base `10`) of *x*.
24 - `Math.e` Returns a floating-point approximation of the number ℯ.
25
26- Trigonometry
27 - `Math.pi` Returns a floating-point approximation of the number *π*.
28 - `Math.deg2rad(x)` converts from degrees to radians.
29 - `Math.rad2deg(x)` converts from radians to degrees.
30 - `Math.sin(x)` The sine of *x*.
31 - `Math.cos(x)` The cosine of *x*.
32 - `Math.tan(x)` The tangent of *x*.
33 - `Math.asin(x)` The inverse sine of *x*.
34 - `Math.acos(x)` The inverse cosine of *x*.
35 - `Math.atan(x)` The inverse tangent of *x*.
36 - `Math.atan2(x, y)` The inverse tangent of *x* and *y*. This variant returns the inverse tangent in the correct quadrant, as the signs of both *x* and *y* are known.
37 - `Math.sinh(x)` The hyperbolic sine of *x*.
38 - `Math.cosh(x)` The hyperbolic cosine of *x*.
39 - `Math.tanh(x)` The hyperbolic tangent of *x*.
40 - `Math.asinh(x)` The inverse hyperbolic sine of *x*.
41 - `Math.acosh(x)` The inverse hyperbolic cosine of *x*.
42 - `Math.atanh(x)` The inverse hyperbolic tangent of *x*.
43
44- Working with Collections
45 - `Math.Enum.product(collection)` The result of multiplying all elements in the passed collection.
46 - `Math.Enum.mean(collection)` the mean of the numbers in the collection.
47 - `Math.Enum.median(collection)` the median of the numbers in the collection.
48
49## Installation
50
51Math is [available in Hex](https://hex.pm/packages/math). The package can be installed by:
52
53 1. Add math to your list of dependencies in `mix.exs`:
54
55 def deps do
56 [
57 {:math, "~> 0.3.0"}
58 ]
59 end
60
61 2. Require or import the Math library anywhere in your code you'd like:
62
63 require Math
64
65 or
66
67 import Math
68
69 (Importing allows usage of the `<~>` operator)
70
71## Changelog
72- 0.3.0 Fixed incorrect median for lists with even number of items. Updated tests.
73- 0.2.0 Added `factorial/1`, `nth_sqrt/2`, `k_permutations/2`, `k_combinations/2`, `gcd/2`, `lcm/2` and `Math.Enum` functions. Improved documentation.
74- 0.1.0 Added integer variant of `pow/1`, `isqrt/2`, `deg2rad/1`, `rad2deg/1`. Improved documentation.
75- 0.0.1 First implementation, mostly a wrapper around Erlang's `:math` library.
76