EmbeddedRelated.com
Forums
The 2026 Embedded Online Conference

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
The 2026 Embedded Online Conference