Discussion:
printf() format for C99 complex type?
Lionel Cons
2013-07-11 17:16:05 UTC
Permalink
Are there any printf() formats defined for the C99 complex type?

Lionel
Fred J. Tydeman
2013-07-11 17:44:51 UTC
Permalink
Post by Lionel Cons
Are there any printf() formats defined for the C99 complex type?
No. Instead, do: printf("(%g+I*%g)", creal(z), cimag(z));


---
Fred J. Tydeman Tydeman Consulting
***@tybor.com Testing, numerics, programming
+1 (775) 287-5904 Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.
Lionel Cons
2013-07-13 06:59:43 UTC
Permalink
Post by Fred J. Tydeman
Post by Lionel Cons
Are there any printf() formats defined for the C99 complex type?
No. Instead, do: printf("(%g+I*%g)", creal(z), cimag(z));
Do any libc versions or operating systems provide extensions to print
this in one go? The problem I'm trying to solve is the lack of way to
distinguish between a plain floating-point number and a complex
number. strtod() will consume only the floating-point part, and then?

Lionel
Fred J. Tydeman
2013-07-13 16:12:14 UTC
Permalink
Post by Lionel Cons
Post by Fred J. Tydeman
Post by Lionel Cons
Are there any printf() formats defined for the C99 complex type?
No. Instead, do: printf("(%g+I*%g)", creal(z), cimag(z));
Do any libc versions or operating systems provide extensions to print
this in one go?
Not as far as I know.
Post by Lionel Cons
The problem I'm trying to solve is the lack of way to
distinguish between a plain floating-point number and a complex
number. strtod() will consume only the floating-point part, and then?
Since a complex number is a pair of floating-point numbers, you could
use strtod() twice to read both numbers and then create you own
complex number from the pair.

---
Fred J. Tydeman Tydeman Consulting
***@tybor.com Testing, numerics, programming
+1 (775) 287-5904 Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.

Loading...