Division: Is there a way to simultaneously find the quotient and remainder?

Sure... see quotRem in the prelude.
On May 6, 2011 10:49 AM,
:)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hoogle is very useful for the kinds of questions where you can
estimate a likely type:
http://www.haskell.org/hoogle/?hoogle=Integral+a+%3D%3E+a+-%3E+a+-%3E+%28a%2...
On Sat, May 7, 2011 at 12:50 AM, Chris Smith
Sure... see quotRem in the prelude.
On May 6, 2011 10:49 AM,
wrote: :)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Chris Smith schrieb:
Sure... see quotRem in the prelude.
http://www.haskell.org/haskellwiki/Haskell_programming_tips#Forget_about_quo...

Thank you all.
I remember Hoogle'ing for "rem" and then "quot" but not finding "qoutRem". :)
On Sat, May 14, 2011 at 6:55 AM, Henning Thielemann
Chris Smith schrieb:
Sure... see quotRem in the prelude.
http://www.haskell.org/haskellwiki/Haskell_programming_tips#Forget_about_quo...
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- -- Regards, KC

On Saturday 14 May 2011 15:55:15, Henning Thielemann wrote:
Chris Smith schrieb:
Sure... see quotRem in the prelude.
http://www.haskell.org/haskellwiki/Haskell_programming_tips#Forget_about _quot_and_rem
No, don't, just know when you want which. quot and rem are what you get from the hardware (perhaps not all, but most), thus they are faster. If speed is important and the semantics coincide (e.g. when all operands are positive), use quot and rem. If the semantics of quot or rem are better for your goal than those of div or mod (example from GHC.Float.floatToDigits: -- Using quot instead of div is a little faster and requires -- fewer fixup steps for negative lx. let lx = p - 1 + e0 k1 = (lx * 8651) `quot` 28738 ), use quot or rem. div and mod have the better semantics for most use-cases, so they should be what one normally uses, but there are cases where you want quot and rem. For those cases, knowing them causes happiness.
participants (6)
-
caseyh@istar.ca
-
Chris Smith
-
Daniel Fischer
-
Henning Thielemann
-
KC
-
Lyndon Maydwell