Alex Rivera | Logout

Is Multiplying the Inverse Better or Worse?

Asked 2009-03-17T18:35:32.847
11

When dealing with double data types is multiplying by the inverse better or worse?

Which way is faster? Which way uses less memory? Which way is preferred?

How does MSIL handle this?

SquareInches = MMSquared / 645.16 
SquareInches = MMSquared * 0.0015500031000062000124000248000496

NB: 10K users will note that this is a duplicate of this question, which was deleted because the original question asker decided to berate everyone in the 'comments' section of the question.

This question was reposted because it is a 'good' question.

Please 'uncheck' Community Wiki for your answer, as I'm only posting this as CW so that it's not seen as a 'reputation' grab.

Related Question:

Should I use multiplication or division?

Edit
Report

2 Answers

11

Which one is "faster" is indeed a cpu-specific issue, or at least how much faster is CPU specific, yes, division is typically seen as slower than multiplication. And of course all performance questions can be answered with "it depends."

HOWEVER, if you'd asked which is "better" rather than which is faster there would be a clear answer, the more readable one is better. The performance improvement you're looking at is likely on the order of several clock cycles, so unless you're talking about doing this millions of times, you're trying to save yourself microseconds. And there is no microsecond optimization that is worth sacrificing readability and maintainability.

answered 2009-03-17T18:50:16.603
0

With most processors, it's faster to multiply than divide. But it's really insignificant for most applications, in my opinion you're better off with whichever is more readable, unless profiling shows it's a critical path.

If it's an interpreted language, the amount of time to read the source and convert it to numbers will overwhelm the time taken to actually do the math, especially if you use that many significant digits for the multiply. (Are you sure you really need that many significant digits?)

answered 2009-03-17T18:44:02.560

Your Answer