Finding limits of functions A limit in math determines the value that a function f(x) approaches as x gets closer and closer to a certain value.

Let me use the equation f(x)=x^2/x as an example.
Obviously, f(x) is undefined if x is 0 (x=0, x2=0, 0/0 is undefined).
But, what happens when we calculate f(x) as x approaches 0?

x=0.1, f(x)=0.01/0.1 = 0.1
x=0.01, f(x)=0.0001/0.01 = 0.01
x=0.00001, f(x)=0.0000000001/0.00001 = 0.00001
We can easily see that f(x) is approaching 0 as x approaches 0.

What about when f(x)=1/x^2, and we approach 0?

x=0.1, f(x)=1/0.01=100
x=0.01, f(x)=1/0.0001=10000
x=0.00001, f(x)=1/0.0000000001=10000000000
As x approaches 0, f(x) approaches positive infinity.

You will be given two things in whatever input format you like:


f(x) as an eval-able string in your language
a as a floating point


Output the value that f(x) approaches when x approaches a. Do not use any built-in functions that explicitly do this.

Input Limitations:


The limit of f(x) as x approaches a will always exist.
There will be real-number values just before and just after f(a): you will never get f(x)=sqrt(x), a=-1 or anything of the sort as input.


Output Specifications:


If f(x) approaches positive or negative infinity, output +INF or -INF, respectively.
If f(a) is a real number, then output f(a).


Test Cases:

f(x)=sin(x)/x, a=0; Output: 1
f(x)=1/x^2, a=0; Output: +INF
f(x)=(x^2-x)/(x-1), a=1; Output: 1
f(x)=2^x, a=3; Output: 8


Shortest code wins. Good luck!
C, 402 bytes

Plenty of room for golfing, just proof of concept to begin with :P

Compiles under clang, osx.

Note: For linux you may have to change the code to use something like: "ld -shared f.o -o f.so -lm"

#include&lt;dlfcn.h&gt;
#include&lt;stdio.h&gt;
float e,r;
main(int i,char**v){
    // create and compile temporary c file for 'f(x)'
    // note: include offset within function
    FILE*s=fopen("f.c","w");
    fprintf(s,"#include&lt;math.h&gt;\nfloat f(float x){x+=%s;return %s;}",v[2],v[1]); 
    fclose(s);
    system("cc -fPIC -c f.c;ld -bundle f.o -o f.so -lm");
    float(*f)(float)=dlsym(dlopen("f.so",0),"f");

    for(i=0;1;e=(e==0)?1e-37:e*2){
        r=f(e);
        if(isinf(r))i=1;else if(!isnan(r)){
            i?printf("%cINF\n",r&gt;0?43:45):printf("%f\n",r);
            break;
        }
    }
}


Run as:

./a.out "sin(x)/x" 0
./a.out "1/(x*x)" 0
./a.out "(x*x-x)/(x-1)" 1
./a.out "pow(2,x)" 3


Results:

1.000000
+INF
1.000000
8.000000