Chris M. Thomasson
2017-05-02 05:27:15 UTC
This compiler just helped me find a bug that compiled right along wrt
GCC 5.1.0 on windows even using: -Wall -pedantic -Wextra -Wall
Take a look at the following c99 crude code and try to find the bug:
____________________
#include <stdio.h>
#include <assert.h>
#include <complex.h>
#include <tgmath.h>
void
ct_iterate_pixel(
double complex z,
double complex c,
unsigned int imax
){
//printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
for (unsigned int i = 0; i < imax; ++i)
{
z = z * z + c;
if (abs(z) > 2)
{
putchar('-');
return;
}
}
putchar('*');
}
void
ct_iterate_plane(
unsigned int width,
unsigned int height,
unsigned int imax
){
assert(width > 1 && height > 1);
double xstep = 4.0 / (width - 1.0);
double ystep = 4.0 / (height - 1.0);
for (unsigned int y = 0; y < height; ++y)
{
for (unsigned int x = 0; x < width; ++x)
{
double complex z = (-2.0 + x * xstep) + I * (2.0 - y * ystep);
//printf("(%u, %u):z = %.1f%+.1fi\n", x, y, creal(z),
cimag(z));
ct_iterate_pixel(z, z, imax);
}
putchar('\n');
}
}
int main(void)
{
ct_iterate_plane(73, 73, 53);
fflush(stdout);
printf("\n\nFin, hit <ENTER> to exit...\n");
getchar();
return 0;
}
____________________
The problem is my call to abs! I need to be using cabs and lcc-win64
found it for me.
Thank you Jacob Navia!
:^)
GCC 5.1.0 on windows even using: -Wall -pedantic -Wextra -Wall
Take a look at the following c99 crude code and try to find the bug:
____________________
#include <stdio.h>
#include <assert.h>
#include <complex.h>
#include <tgmath.h>
void
ct_iterate_pixel(
double complex z,
double complex c,
unsigned int imax
){
//printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
for (unsigned int i = 0; i < imax; ++i)
{
z = z * z + c;
if (abs(z) > 2)
{
putchar('-');
return;
}
}
putchar('*');
}
void
ct_iterate_plane(
unsigned int width,
unsigned int height,
unsigned int imax
){
assert(width > 1 && height > 1);
double xstep = 4.0 / (width - 1.0);
double ystep = 4.0 / (height - 1.0);
for (unsigned int y = 0; y < height; ++y)
{
for (unsigned int x = 0; x < width; ++x)
{
double complex z = (-2.0 + x * xstep) + I * (2.0 - y * ystep);
//printf("(%u, %u):z = %.1f%+.1fi\n", x, y, creal(z),
cimag(z));
ct_iterate_pixel(z, z, imax);
}
putchar('\n');
}
}
int main(void)
{
ct_iterate_plane(73, 73, 53);
fflush(stdout);
printf("\n\nFin, hit <ENTER> to exit...\n");
getchar();
return 0;
}
____________________
The problem is my call to abs! I need to be using cabs and lcc-win64
found it for me.
Thank you Jacob Navia!
:^)