Hello I have some difficulties with the ceil function in c++ :
I've got a regular grid of points, and I need to perform an interpolation over it to compute the z-values of a set of points.
In order to do that, I need, for each computed point, to get the nearest points on the grid. I do it like this :
y1 = dy*floor(p.y/dy);
y2 = dy*ceil(p.y/dy);
where dy is the space beetween two points of the grid. (y1, p.y and dy are double) If I display the results using
cout << static_cast<double>(p.y/dy) << ": " << y1 << ", " << y2 << endl;
I've got these strange results :
0: 0, 0
1: 0.1, 0.1
2: 0.2, 0.2
3: 0.3, 0.4
The three first results are OK but the last one is wrong and make an assertion fail.
I would like to know where did this strange error came and how to avoid it. Thanks.
I apologize for my English
EDIT
I call the function with dy = 0.1, but during the execution, it take the folowing value dy = 0.10000000000000001. p.y is initialized like that :
const uint N = round((x2 - x1) / dx2);
const uint M = round((y2 - y1) / dy2);
double p = persistence;
double n = number_of_octaves;
// generation of the points where the perlin noise is generated
std::vector<Vertex3d> ret;
std::vector<Vertex3d> dummy;
for (uint i=0;i<=N;++i)
{
for (uint j=0;j<=M;++j)
{
ret.push_back({.x = i*dx2, .y=j*dy2, .z=0});
dummy.push_back({.x = i*dx2, .y=j*dy2, .z=0});
}
}
where x1 = 0 and x2 = 1 (according gdb)