/* Split this file in 3 separate file, c_main.c, c_quot.h and c_quot.c. Compile with and without optimization using Sun C 5.8 compiler on Solaris 10 (Opteron) and run as follows. > rm a.out ; cc -xtarget=native64 -xO0 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 6.643856 + j 0.000000 > rm a.out ; cc -xtarget=native64 -xO1 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 6.643856 + j 0.000000 > rm a.out ; cc -xtarget=native64 -xO2 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 6.643856 + j 0.000000 > rm a.out ; cc -xtarget=native64 -xO3 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 Inf + j 0.000000 > rm a.out ; cc -xtarget=native64 -xO4 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 Inf + j 0.000000 > rm a.out ; cc -xtarget=native64 -xO5 c_main.c c_quot.c -lm ; ./a.out c_main.c: c_quot.c: 6.643856 + j 0.000000 Inf + j 0.000000 */ ------------------ save as c_main.c ----------------- #include #include "c_quot.h" int main(int argc, char* argv[]) { complex_t x, y, q, r; x = c_comp(4.6051701859880918); y = c_comp(0.69314718055994529); q = c_quot(x, y); /* expect: 6.643856 + j 0.000000 */ printf("%f + j %f\n", q.real, q.imag); x = c_comp(4.6051701859880918); y = c_comp(0.69314718055994529); r = c_quot(x, c_comp(0.6931471805599452)); /* expect: 6.643856 + j 0.000000, but ... */ printf("%f + j %f\n", r.real, r.imag); } ------------------ save as c_quot.h ----------------- typedef struct { double real; double imag; } complex_t; complex_t c_comp(double real); complex_t c_quot(complex_t a, complex_t b); ------------------ save as c_quot.c ----------------- #include "c_quot.h" complex_t c_comp(double real) { complex_t c; c.real = real; c.imag = 0.0; /* ignore imag */ return c; } complex_t c_quot(complex_t a, complex_t b) { complex_t r; r.real = a.real / b.real; r.imag = 0.0; /* ignore imag */ return r; }