以下のC関数の違いを教えてください。
static int mandel(float c_re, float c_im, int count) {
float z_re = c_re, z_im = c_im;
int i;
for (i = 0; i < count; ++i) {
if (z_re * z_re + z_im * z_im > 4.f)
break;
float new_re = z_re*z_re - z_im*z_im;
float new_im = 2.f * z_re * z_im;
z_re = c_re + new_re;
z_im = c_im + new_im;
}
return i;
}
そして、次の
static int mandel(float c_re, float c_im, int count) {
float z_re = c_re, z_im = c_im;
int i;
for (i = 0; i < count; ++i) {
if (z_re * z_re + z_im * z_im > 4.f)
break;
float new_im = 2.f * z_re * z_im;
z_re = c_re + z_re*z_re - z_im*z_im;//I have combined the statements here and removed float new_re
z_im = c_im + new_im;
}
return i;
}
コードの変更については、私のコメントを参照してください。関数は、一部の入力に対して異なる値を返します。2 つのステートメントを組み合わせたためにフロートがずれていますか?