I will give some context to the function that I wrote:
getFractalPointHeight() is a function that is supposed to return the height of the fractal noise based on the coordinates of a Perlin noise image and the other 2 values amplitude and frequency
To get the height from the perlin noise I use the function getPointHeight().
The perlin noise is a grid of length nodesxn - 1 * nodesyn - 1.
The four whiles I wrote in the function are supposed to change the coordinates in case they are outside the perlin noise boundaries however it doesn't tile correctly as shown in the image above
float getFractalPointHeight(float x,float y,int octaves,float amplitude,float frequency){
float elevation = amplitude;
for(int i = 0;i<octaves;i++){
float sx = x * frequency;
float sy = y * frequency;
while(sx < 0){
sx = sx + (nodesxn - 1);
}
while(sy < 0){
sy = sy + (nodesyn - 1);
}
while(sx > nodesxn - 1){
sx = sx - (nodesxn - 1);
}
while(sy > nodesyn - 1){
sy = sy - (nodesyn - 1);
}
elevation += getPointHeight(sx,sy) * amplitude;
frequency *= 2;
amplitude *= 0.5;
}
elevation = fmin(2,fmax(elevation,0));
return elevation;
}

I found out what the problem was: The perlin noise I generated wasn't seamless. I made the vectors at the edges of the perlin noise grid identical and now the fractal noise looks fine