Math libarary



I wrote a routine to replace Math's Exp method but it turns out to be almost
2x slower ;/ (well, actually its about 1.5x in release)

I'm essentially using a lookup table and interpolate between integer
values(but even just looking up its still as slow).

public static double Exp(double x)
{
int n = (int)Math.Floor(x);
//if ((n > 2351) || (n < -2351)) return Math.Sign(x) *
double.PositiveInfinity;

double f = x - n;
double ff = 1;
double e = 1;

if (f != 0)
for (int i = 1; i < 10; i++)
{
ff = ff * f;
e += invnfac[i] * ff;
}

return ExpIp[n + 2351]*e;
}

What I did was precompute n! and ExpIp is exp(k) for integer k. exp(+-2351)
is the maximum that a double can hold so no reason to go beyond that.

If I comment out the loop I get almost there speed but still about 1%
slower.

How the hell are they computing so fast? Normally these Math library
routines are very slow but either my code/method sucks or Math .NET is
fairly optimized?

Anyone know whats going on here?

Thanks,
Jon


.



Relevant Pages

  • Re: 2D interpolation from trinagular mesh to coarser (arbitrary) triangular
    ... Anybody any hints on where to find a routine that will known read x,y, ... value and interpolate on a new x_n, ... triangular grid. ... interpolate in the coarse grid using these data as input 2, ...
    (sci.math.num-analysis)
  • Re: Checking for NaN
    ... I have a very unique way to interpolate. ... So, I will use isnan(). ... happen to know if there is a routine that would return the indices of ... directly to the NaN locations instead of searching through the matrix). ...
    (comp.soft-sys.matlab)
  • Re: Make yield_task_fair more efficient
    ... This patch makes the routine more efficient by ... reducing the cost of the lookup ...
    (Linux-Kernel)
  • Re: Lookup in a table
    ... This will allow you to specify a field in a table or ... Wayne Morgan ... > box to do a lookup. ... It's a routine that is adding a many ...
    (microsoft.public.access.formscoding)
  • Re: About speed
    ... After converting types in lookup tables and in the function i tested the routine to make sure that i am getting the same results. ... I am measuring 7 cards evaluator inlined and un-inlines. ...
    (borland.public.delphi.non-technical)