Andy Ross writes: > > Vivian Meazza wrote: > > I used the power form because it is easier to read, but if the other > > form produces a performance advantage, then of course we must use > > it. > > It's actually not so much about performance, really. Readability can > mean different things. The problem is that when I see a trancendental > function in code, I immediately start thinking that it much be some > complicated formula typed in from a book, as these things don't occur > in typical programmer's brains all that often. Basically, even though > in isolation it's easier to read "pow(foo, 3)" than "foo*foo*foo", > when you look at the whole expression, your original one is > "complicated" to me: > > (-0.25 * math::pow(rpm_norm,3)) + (-0.15 * math::pow(rpm_norm,2)) > + (1.11 * rpm_norm); > > Whereas this one is just really obviously a polynomial, and I > understand polynomials, they're simple and not scary at all: > > rpm_norm * (1.11 - rpm_norm * (0.15 * rpm_norm + 0.25)) > > I'll work up a version of the new one with the sign bug fixed, and try > to get that checked in tonight.
Hmmm..... I find it all to easy to make silly mistakes with nested parentheticals and usually avoid them unless absolutely needed Python 2.4 (#1, Dec 4 2004, 20:10:33) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> rpm_norm = 100 >>> a = (-0.25 * math.pow(rpm_norm,3)) + (-0.15 * math.pow(rpm_norm,2)) + (1.11 >>> * rpm_norm) >>> b = rpm_norm * (1.11 - rpm_norm * (0.15 * rpm_norm + 0.25)) >>> a == b False >>> a -251389.0 >>> b -152389.0 >>> rpm_norm_2 = rpm_norm*rpm_norm >>> rpm_norm_3 = rpm_norm * rpm_norm_2 >>> c = (-0.25*rpm_norm_3) + (-0.15*rpm_norm_2) + (1.11*rpm_norm) >>> a == c True >>> _______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d