Skip to content

Commit

Permalink
mix format, update docs. 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
q60 committed Aug 19, 2022
1 parent 451d766 commit d31f543
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions lib/rational.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Rational do
* multiplication
* division
* power
* absolute value
## Some examples
Expand Down Expand Up @@ -36,13 +37,15 @@ defmodule Rational do
quote do
import Kernel, except: [+: 2, -: 2, *: 2, /: 2, **: 2, abs: 1]
import RationalMath
import Rational, only: [sigil_n: 2, parse: 1, compare: 2]
import Rational, only: [is_rational: 1, sigil_n: 2, parse: 1, compare: 2]
end
end

defstruct [:num, :denom]

@type rational() :: %Rational{num: number(), denom: number()}
@typedoc false
@type operator() :: :+ | :- | :* | :/ | :**
defstruct [:num, :denom]

@doc """
Returns `true` if `term` is a rational, otherwise returns `false`.
Expand Down Expand Up @@ -103,11 +106,11 @@ defmodule Rational do
"""
@spec compare(rational(), rational()) :: :lt | :eq | :gt
def compare(a, b) do
case {a.num / a.denom, b.num / b.denom} do
{first, second} when first > second ->
case {a.num / a.denom, b.num / b.denom} do
{first, second} when first > second ->
:gt

{first, second} when first < second ->
{first, second} when first < second ->
:lt

_ ->
Expand Down Expand Up @@ -189,8 +192,11 @@ defmodule Rational do
|> result()
end

@doc false
@spec op(rational(), :abs) :: rational()
def op(a, :abs) when is_rational(a), do: %Rational{num: abs(a.num), denom: abs(a.denom)}
def op(a, :abs) when is_number(a),do: abs(a)
@spec op(number(), :abs) :: number()
def op(a, :abs) when is_number(a), do: abs(a)

defp gcd(a, 0), do: abs(a)
defp gcd(a, b), do: gcd(b, rem(a, b))
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Rational.MixProject do
def project do
[
app: :rational,
version: "1.3.0",
version: "1.3.1",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
description: description(),
Expand Down

0 comments on commit d31f543

Please sign in to comment.