The constant is Math.E
, not Math.e
Math.pow() floating point number as exponent [closed]
-
03-04-2022 - |
Question
I want to pass a floating-point number as the second argument (exponent) to Math.pow()
. I always get NaN
when the passed number is not a whole number, like 0, 2, 7, you name it. Is there a working way in javascript to make this work?
(function () {
var notice = document.getElementById('notice');
var value = 0.0;
var interval = 0.02;
var timeInterval = 10;
function interpolation(x) {
var y = Math.pow(Math.e, x); // <<< HERE >>>
console.log(x, y);
return y;
}
function animation() {
var callAgain = true;
if (value >= 1) {
value = 1.0;
callAgain = false;
}
notice.style['opacity'] = interpolation(value);
notice.style['marginTop'] = (value * 20 + 20) + 'px';
value += interval;
if (callAgain) {
setTimeout(animation, timeInterval);
}
}
animation();
})();
PS: Please don't comment, that an opacity greater than 1 doesn't make any sense. I know that e^x; x > 0
will yield values greater than 1
. I'll insert a proper function when I got this working.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow