Java programming (data types) question

I’m having an issue with a particularly lengthy mathematical function.

The function is e^(-x^2) + 1, coded as

(float)(Math.exp(Math.pow(evalPoint, 2.0) * -1) + 1); because I need it returned to me as a float.

I implemented this equation in a static method within my main program and I was getting the right answer for my test points.

The problem arose when I moved this function out into another class as part of an interface implementation. Now when I test the function I’m getting answers that are way off what they should be. When evaluating this equation at x=2, the proper answer is 1.01, but through the interface I’m getting an answer of 2.41.

Anyone know what the issue may be? Could it possibly be an issue with the fact that Math.pow and Math.exp normally take doubles but I’m passing in floats and then casting to a float for the final answer?

Any help would be greatly appreciated!

Are you certain that’s what you’re passing in and getting out of the function? Because casting to float shouldn’t cause that much error. My first thought is that the bug is actually somewhere else.

Well there’s another function I’ve done the same thing with and not had any trouble.

sin(|x|) + 1 coded: (float)Math.sin(Math.abs(evalPoint)) + 1;

Nevermind, looks like it was just an issue with some switch statement code.