"Well... I should probably apply it to my calculation of "log(x)/log(2 to the power of (1/12))" in Open Theremin with MIDI." - Mr_Dham
With log(x) / log(2^(1/12)) the denominator is a constant, so it is probably evaluated at compile time rather than run time. And division by a constant is multiplication by its inverse, so the otherwise time consuming division is likely just a multiplication. In the Hive math libraries I've only implemented log2 and exp2 (i.e. nothing based on the constant e) as they are the easiest and fastest to calculate in binary, and are the most useful. On a 32 bit machine, log2 can actually be accomplished using only shifts and subtracts to produce a result within 0.3%, and on Hive this takes 9 cycles max. Using a simple change of variable and a second order polynomial gets the error down to +/-0.025% (for larger integer inputs) and uses 13 cycles max. These are all integer input, producing a 5.27 fixed point output.
That said, I don't see that log2, of ANY precision, is used anywhere in the D-Lev code base. The field linearization maths also make the pitch and volume numbers linear, so there is just exp2 at the end of it all for our conveniently doubly logarithmic (i.e. pitch and volume) ears. For the exp2 the code uses low quality (+/-0.0005% error, 4th order poly, 18 cycles) and very low quality (+/-0.33% error, 2nd order poly, 12 cycles). The desired quality is selected by calling the specific subroutine, I wonder if there is any way to explicitly control this in the OpenTheremin code? Higher level languages tend to get in the way of one micromanaging the maths and value representations themselves.
There is a rather trivial non-polynomial version of exp2 as well that only requires 7 cycles, but the error is 6.15% for larger inputs. Clearly, log2 is somewhat more amenable to calculation than exp2.
Floats add a ton of overhead too, so I've very deliberately and laboriously avoided them whenever possible, sticking to ints and fracs (<1) though that can get pretty tricky. Put enough elbow grease into it up front and you can put a man on the moon with a pocket calculator! :-)