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 aneval
-able string in your languagea
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)
asx
approachesa
will always exist. - There will be real-number values just before and just after
f(a)
: you will never getf(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 outputf(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!
f(x)=1/x
anda=0
\$\endgroup\$The limit of f(x) as x approaches a will always exist.
\$\endgroup\$