All right! It took most of today, but I've solved the problem!
*Problem:* Elixir does not have a (guard-safe) Floored Modulo Remainder
function `mod`.
*Proposed solution:* Implement with floored division, as follows:
mod(a, n) === a - (n * floor_div(a, n))
*Subproblem:* Elixir does not have
>
> why not use *-1, 0, 1* instead of* :lt, :eq, :gt*?
>
Saying that using atoms is the Elixir equivalent of Haskell's Ord does not
make a lot of sense, I believe; Elixir does not have static types, so any
agreed-upon triple of values is equally valid to represent the different
possibilities
I have tried to implement a guard safe version this in the past, to no
avail. The limitation that I can remember was to not to be able to use
a conditional in the guards, which let me to create conditionals using
boolean operators.. it didn't work.
I will be happy to see a solution.
On Mon, 8
> On 08 Aug 2016, at 03:36, Paul Schoenfelder
> wrote:
>
> Just my two cents, but why would this function return atoms instead of -1, 0,
> 1? Then it works easily with sorting functions, and is consistent with
> compare implementations in other languages.
There’s
I have been fiddling around with this for quite some time. Other than I
thought, `div` also uses truncated division. (It makes sense, as it
complements `rem`). This makes above implementation moot.
To be able to create `mod`, we need a floored division. I have not yet
found a way to do this
Yes, please send a pull request. :)
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R
On Mon, Aug 8, 2016 at 10:24 AM, Wiebe-Marten Wijnja <
w.m.wij...@panache-it.com> wrote:
> Elixir has `rem(dividend, divisor)` to calculate the remainder of an
> integer
Elixir has `rem(dividend, divisor)` to calculate the remainder of an
integer division. However, as you probably know, there are different ways
to handle remainders with negative numbers:
`rem` will take the remainder, but use the sign of the dividend, which
means that the following function