EmbeddedRelated.com
Forums
Jacob Beningo
Live online course · Jacob Beningo
AI for Embedded Developers
$100 off for EmbeddedRelated readers until Nov 1 · 5 live sessions, Dec 7-11
Discount ends in
16days 07hrs 23min 31sec
Learn More →

Slightly OT: speed of operation on a PC

Started by Tim Wescott ●August 4, 2015
On 04.08.2015 20:06, Lanarcam wrote:
> Le 04/08/2015 19:59, Tim Wescott a &eacute;crit : >> Which do you think is quicker on a PC, with the latest gnu compiler: >> >> double a = something; >> double b = something else; >> >> if (a >= 0.0 && b < 0.0) >> >>>> or << >> >> if (a * b <= 0) >> >> Thank you for your time. >> > if (a + b < a) would be quicker, I believe.
Why would it? Depending on the architecture, comparing with 0 is often more efficient than with other values. Also multiplication is a much simpler operation than addition for floating-point values. Philipp
On 04.08.2015 23:30, Hans-Bernhard Br&ouml;ker wrote:
> Am 04.08.2015 um 19:59 schrieb Tim Wescott: >> Which do you think is quicker on a PC, with the latest gnu compiler: >> >> double a = something; >> double b = something else; >> >> if (a >= 0.0 && b < 0.0) >> >>>> or << >> >> if (a * b <= 0) > > That's rather beside the point, I'm afraid. Those two expressions don't > even compute the same condition, so who cares which of them might be > quicker?
They might be equivalent for the OP. The OP might have additional knowledge on the values of a and b. Philipp