[Haskell-beginners] division / multiplication efficiency

Christopher Howard christopher.howard at frigidcode.com
Wed Nov 28 14:02:38 CET 2012

Say I have functions like so:

circleRadians = 2 * pi

radius = (/ circleRadians)

My question: each time I call radius, will a division operation be
performed? Is there anything to be gained, following the old adage that
multiplication is more efficient than division in hardware, from
something like:

radius = (* (1 / circleRadians))

...imagining that the compiler (or runtime graph reduction mechanism)
will transform (1 / circleRadians) into a single number (s) only once,
and use (* s) in all applications of radius?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121128/5e238bd2/attachment.pgp>

More information about the Beginners mailing list