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.
f(x) is undefined if x is 0 (x=0, x2=0, 0/0 is undefined).
But, what happens when we calculate
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 approaches 0,
f(x) approaches positive infinity.
You will be given two things in whatever input format you like:
eval-able string in your language
aas a floating point
Output the value that
f(x) approaches when
a. Do not use any built-in functions that explicitly do this.
- The limit of
awill always exist.
- There will be real-number values just before and just after
f(a): you will never get
f(x)=sqrt(x), a=-1or anything of the sort as input.
f(x)approaches positive or negative infinity, output
f(a)is a real number, then output
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!