Re: default for quotRem in terms of divMod?

Btw. is there any application, where 'quot' and 'rem' are needed? All occurrences of 'quot' and 'rem' I found in code so far were actually wrong and should have been 'div' and 'mod'. http://www.haskell.org/haskellwiki/Things_to_avoid#Forget_about_quot_and_rem

On Sat, 2007-08-11 at 21:10 +0200, Henning Thielemann wrote:
Btw. is there any application, where 'quot' and 'rem' are needed? All occurrences of 'quot' and 'rem' I found in code so far were actually wrong and should have been 'div' and 'mod'.
http://www.haskell.org/haskellwiki/Things_to_avoid#Forget_about_quot_and_rem
quotRem is faster than divMod, and my understanding is that even divMod is arguably broken. http://www.cs.uu.nl/~daan/download/papers/divmodnote-letter.pdf

On Sat, 11 Aug 2007, Derek Elkins wrote:
On Sat, 2007-08-11 at 21:10 +0200, Henning Thielemann wrote:
Btw. is there any application, where 'quot' and 'rem' are needed? All occurrences of 'quot' and 'rem' I found in code so far were actually wrong and should have been 'div' and 'mod'.
http://www.haskell.org/haskellwiki/Things_to_avoid#Forget_about_quot_and_rem
quotRem is faster than divMod,
Seems that CPU design should be changed.
and my understanding is that even divMod is arguably broken.
In what way? I can't deduce it from your reference. Quote: "Boute argues that Euclidean division is superior to the other ones in terms of regularity and useful mathematical properties, although floored division, promoted by Knuth, is also a good definition. Despite its widespread use, truncated division is shown to be inferior to the other definitions."
http://www.cs.uu.nl/~daan/download/papers/divmodnote-letter.pdf
Thanks for the reference!

Henning Thielemann wrote:
Btw. is there any application, where 'quot' and 'rem' are needed? All occurrences of 'quot' and 'rem' I found in code so far were actually wrong and should have been 'div' and 'mod'.
http://www.haskell.org/haskellwiki/Things_to_avoid#Forget_about_quot_and_rem
Yes, my implementation of Integer in terms of lists of Int, deliberately uses the symmetry of quotRem in order to store negative numbers as the negation of all elements of the positive number, and be able to virtually ignore the signs most of the time. (Also because quotRem is usually faster, I figured it made sense to use that technique.) (It doesn't make any difference on numbers that cannot be negative, also.) Everywhere else I remember when coding, div/mod were the correct ones to use (even back when I was coding in C, I wished I had that rounding behavior some time). I do think that if you almost always want to _use_ div and mod, you should be able to just define div and mod too (not quot and rem) -- one reason I brought up the issue :) Isaac

Isaac Dupree wrote:
I do think that if you almost always want to _use_ div and mod, you should be able to just define div and mod too (not quot and rem)
that was unclear - I mean you should have that choice, not that it should be disallowed to define quot and rem only! Isaac
participants (3)
-
Derek Elkins
-
Henning Thielemann
-
Isaac Dupree