Your explanation was cut off. How is rem insufficient?
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20151025164416.1a2492aa.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.
There is a difference between modulus and remainder. For example:-21mod4is3because-21 + 4 x 6is3.
But-21divided by4gives-5with a remainder of-1.
For positive values, there is no difference.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAOMhEnzJtk9C6ySSpUiSqcKT9DrscG11%3DoaXaMz3MUN89egMWw%40mail.gmail.com.
Mathematically there is no difference between 3 and -1 in the modular arithmetic.(i.e. adding 3 to a number mod 4 is the same as subtracting 1 mod 4 )The only difference between rem and mod is the user's expectation of the result.You can write a perfectly fine GCD algorithm using rem. Any math you do shouldn'tcare, the problem comes when you take the math and apply it else where.I'd guess the reason mod is always positive in most languages relates to theproblem is where want to cycle through an array inlanguages that do not allow negative array values.Is there any place in Elixir where you'd module arithmetic to get an "array index" thatdoesn't understand that -1 is counting back from the end of the "array"?Regardless, your implementation seems overly complex to me, all you need is
The reason why 'rem' is called 'rem' because that is what the '%' did in C, at least the C's we were working with. We felt it was better to get the name right. :-)
Robert
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/XGDA_EPgPRY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/cc004c65-6300-4c4b-822d-f36beb4398aa%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20151026034702.22385929.eksperimental%40autistici.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20151027222935.55a49cd6.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.