I am facing an interesting issue with my code. When I hard code a number into the script to find the derivative at a specific point, it gives me the correct answer. However, if I use a variable with the same number in the script, the result is completely wrong.
HTML
Point<br>
<input type="text" name="point" id="point" class="form"><br>
<p id="submit" onclick="submit()" name="solve">click</p><br>
Script
<script type="text/javascript>{
function diff(f) {
return function(x) { return (f(x+.0000000001)-f(x))/.0000000001 };
}
function f(x) {
return x*x+2*x+1;
}
fprime = diff(f);
function submit() {
var point = document.getElementById("point").value;
console.log(point); //-0.5
var q = fprime(-0.5); //Will output 1
var w = fprime(point); //Will output 749999998.98
}
Do you have any insights on why this discrepancy is happening and how I can fix it?