gingerBill / gb

gb single-file public domain libraries for C & C++
597 stars 47 forks source link

Improving Quality of Exponential and Logarithm Functions #39

Open kphillisjr opened 6 years ago

kphillisjr commented 6 years ago

I was looking over the various math functions and noticed that there is a lot of error in the implementation of the Logarithm and Exponential functions. This is after applying the Intrinsic-free version of the square root function.

// The Square-Root Function.
sqrtf(x);
// Fast and Simple alternative... 
expf(0.5f*logf(x));

// the Power function
powf(a, b);
// alternative method:
expf(b*logf(a));

Now as far as improving the Accuracy of the Exponential and Logarithm Functions. I suggest looking into the work completed by Ping Tak Peter Tang in the following series of articles from the early 1990s and late 1980s.

Edit: Added note about alternative method for calling the pow function.

gingerBill commented 6 years ago

I was looking over the various math functions and noticed that there is a lot of error in the implementation of the Logarithm and Exponential functions. This is after applying the Intrinsic-free version of the square root function. ...

@kphillisjr these functions are meant to be fast operations rather than precise ones. They are to be used when x is small.

Sent with GitHawk

kphillisjr commented 6 years ago

Thanks for the response, and I found a good alternative ( see: https://github.com/yui0/slibs/blob/master/fmath.h ). I just have not tested the overall speed just yet.