I want to get a class which provides a range of decimal values.
Due to specification of floating point number, returned range object doesn't have accurate values.
To get more precise result like [0.60,0.61,0.62...0.69] returned by python's numpy.arange(0.6,0.7,0.01)
my code is shown below.
// Java range
public class range{
private double start;
private double end;
private double step;
public range(double start,double end, double step) {
this.start = start;
this.end = end;
this.step = step;
}
public List<Double> asList(){
List<Double> ret = new ArrayList<Double>();
for(double i = this.start;i <= this.end; i += this.step){
ret.add(i);
}
return ret;
}
}
Could you have any idea or smarter way to avoid the problem?
And, I hope to get the implementation with only java standard library.