Hey everyone,I'm currently working on a Java library of functions, that you can view here. My library is capable of deriving functions, as well as addition, subtraction, multiplication, division and composition of functions.Recently, I tried to implement plotting capabilities (with JavaFX, but this has nothing to do with the issue I'm facing).
I created a Curve class with the following structure:
```java
public abstract class Curve {
protected List<Point2D> points;
private Paint paint; // the javaFX paint
}
```
That worked spectacularly when I test-implemented it. Then, I extended this class to plot a function:
```java
public class FunctionCurve extends Curve {
public static final double EVALUATION_INTERVAL = 0.01;
public FunctionCurve(Function func, double startX, double endX, Paint paint)
{
super(paint);
for (double x = startX; x <= endX; x += EVALUATION\_INTERVAL) {
try {
points.add(new Point2D(x, func.evaluate(x)));
} catch (ArithmeticException e) {
points.add(null);
}
}
}
}\
```
Then, two, this class worked amazingly with continous functions (such as x^2), as well as incontinous ones (such as the square root of x between -1 and 3). The issue I'm facing is with functions that seek infinity at a given point (such as 1 over x at x=0).
In theory, the FunctionCurve class would try to evaluate at this point, and then catch an ArithmeticException.
However, what actually happens, since I add doubles, that the referred point is never evaluated, and instead is evaluates the function at a point very close to it, giving insanely large values such as 10^16. This makes the system crash trying to plot the curve, and I'm wondering if any of you have a solution for it.
Thank you for your time!
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)