Q: division vs multiplication

t.hulek@imperial.ac.uk (Mr Tomas Hulek)
Fri, 24 Mar 1995 09:42:31 GMT

          From comp.compilers

Related articles
Q: division vs multiplication t.hulek@imperial.ac.uk (1995-03-24)
Re: Q: division vs multiplication kptben@aol.com (1995-04-02)
Re: Q: division vs multiplication Terje.Mathisen@hda.hydro.com (1995-04-02)
Re: Q: division vs multiplication mikeq@primenet.com (1995-04-02)
Re: Q: division vs multiplication hbaker@netcom.com (1995-04-03)
Re: Q: division vs multiplication davidm@Rational.COM (1995-04-03)
Re: Q: division vs multiplication brandis@inf.ethz.ch (1995-04-04)
[12 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: t.hulek@imperial.ac.uk (Mr Tomas Hulek)
Keywords: arithmetic, optimize
Organization: Imperial College of Science, Technology and Medicine, London
Date: Fri, 24 Mar 1995 09:42:31 GMT

It is presumably well known that on many hardware platform floating point
division is slower than floating point multiplication. This means (using C),
that


double a, b, r, s, tmp;


tmp = a/b;
r *= tmp;
s *= tmp;


is in most cases faster than


tmp = b/a;
r /= tmp;
s /= tmp;






My question is: does this also apply to division by constants that are powers
of 2? For real-world compilers (C,C++ let's say) and machines, is there any
benefit in using


r = 0.5*(a+b);


rather than


r = (a+b)/2.0;


???


I would imagine that division by 2.0 could be done very efficiently, just like
division by 10 in our decimal system. But is it really so?


--
Tomas Hulek --------------------------------------------------t.hulek@ic.ac.uk
Mechanical Engineering Dept.
Imperial College
London SW7 2BX tel. (+44 171) 589 5111 x 57112
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.