473,785 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex numbers and printf

The C99 standard forgot to define the printf equivalent for complex numbers
Since I am revising the lcc-win implementation of complex numbers
I decided to fill this hole with
"Z"

for instance
double _Complex m = 2+3*I;
printf("%Zg\n", m);
will print
2+3*I

The alternative flag makes this look like:

printf("%#Zg\n" ,m);
2.00000+3.00000 i

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #1
25 9728

"jacob navia" <ja***@nospam.c omwrote in message
news:fq******** **@aioe.org...
The C99 standard forgot to define the printf equivalent for complex
numbers
Since I am revising the lcc-win implementation of complex numbers
I decided to fill this hole with
"Z"

for instance
double _Complex m = 2+3*I;
printf("%Zg\n", m);
will print
2+3*I

The alternative flag makes this look like:

printf("%#Zg\n" ,m);
2.00000+3.00000 i
I don't think it's quite like that, Jacob, much like the dinner I ingested
on the Champs d'Elyzee. Unlike those 6 chefs 2 dieners, who knew to feed my
wife excellent cuisine while they fed me a horse's willy that I either gave
to my shirt pocket or to the sidewalk on our way back to the hotel, I
actually expected a meal.

I'd be interested to try a new version of lcc.

--
Gerry Ford

"Er hat sich georgiert." Der Spiegel, 2008, sich auf Chimpy Eins komma null
beziehend.
Feb 29 '08 #2
In article <12************ **@news.newsgro ups.com>, "Gerry Ford" <in*****@invali d.netwrote:
>I don't think it's quite like that, Jacob, much like the dinner I ingested
on the Champs d'Elyzee. Unlike those 6 chefs 2 dieners, who knew to feed my
wife excellent cuisine while they fed me a horse's willy that I either gave
to my shirt pocket or to the sidewalk on our way back to the hotel, I
actually expected a meal.
In future, please sober up before posting. Thank you.
Feb 29 '08 #3
Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #4
jacob navia wrote:
Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?
Would it give a diagnostic if called in conforming mode?

Bye, Jojo
Feb 29 '08 #5
jacob navia wrote:
Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?
You initial post sounded quite matter-of-factly and not like e request for
comments...
Feb 29 '08 #6
Joachim Schmitz wrote:
jacob navia wrote:
>Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?
You initial post sounded quite matter-of-factly and not like e request for
comments...

Excuse me. I should have request comments more explicitely.

I hope I do not mess something else. I used "Z" since in the lasts
discussions (about my "b" extension) people complained that it was a
lower case letter. Then I used now upper case ones.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #7
Joachim Schmitz said:
jacob navia wrote:
>Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?
Would it give a diagnostic if called in conforming mode?
No diagnostic message is required for invalid format specifiers to printf.
The behaviour is undefined, and implementations can do anything they like
as a consequence. In lcc-win32, maybe the implementation will treat the
argument as a complex number. Perhaps under some other implementation
it'll format the hard disk. Life gets exciting when you allow your code to
rely on non-standard extensions and then re-compile the code in a
different environment.

I'm not quite sure why this thread is cross-posted to comp.lang.c - it
seems to be an entirely lcc-related subject.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Feb 29 '08 #8
On Fri, 29 Feb 2008 15:50:17 +0100, jacob navia wrote:
Gerry Ford wrote:

[bad dinner left a lasting impression]

Coming back to complex numbers... Any comments?
What about complex numbers?
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Feb 29 '08 #9
On Fri, 29 Feb 2008 10:34:17 +0100, jacob navia wrote:
The C99 standard forgot to define the printf equivalent for complex
numbers
Since I am revising the lcc-win implementation of complex numbers I
decided to fill this hole with
"Z"

for instance
double _Complex m = 2+3*I;
printf("%Zg\n", m);
will print
2+3*I

The alternative flag makes this look like:

printf("%#Zg\n" ,m);
2.00000+3.00000 i
Is it worth doing this? I mean is there a good reason to make the
programmer remember an extra formatting option that's non standard
instead of allowing him to use what he already knows? I mean doing printf
("%f+%f*I\n",re al(m),imag(m)) is not that big of an effort, is it?
However, if you really want to have this formatting option it's probably
a good idea to talk to the guys in comp.std.c and see if they are
considering something like that and whether or not your implementation
may be affected by the standard in the future.


--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Feb 29 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3169
by: Chris Travers | last post by:
Hi all; I just made an interesting discovery. Not sure if it is a good thing or not, and using it certainly breakes first normal form.... Not even sure if it really works. However, as I am able to CRASH the backend, there is a bug here somewhere... test=# select version(); version
6
2260
by: gc | last post by:
Hi, Why didn't the committee propose a new type for complex numbers with integer components? thanks, gc
4
10765
by: Mantorok Redgormor | last post by:
With what specifier do I use to print a variable of a complex type? The man page for printf doesn't even say. - nethlek
7
4141
by: Don Tucker | last post by:
Hello, I have the following test program that I can compile with gcc, but when I try to compile with the portland group compiler, pgcc, I get a stream of errors. #include <stdio.h> #include <complex.h> int main(int argc, char **argv){ complex double a={2.3+1.4*_Complex_I}; printf("a=%lf + i%lf\n",creal(a),cimag(a));
3
2061
by: Russ | last post by:
I'd like to get output formatting for my own classes that mimics the built-in output formatting. For example, >>> x = 4.54 >>> print "%4.2f" % x 4.54 In other words, if I substitute a class instance for "x" above, I'd like to make the format string apply to an element or elements of the instance. Can I somehow overload the "%" operator for that? Thanks.
27
2591
by: David Marsh | last post by:
I understand that C99 supports a complex type and complex arithmetic. There is nothing about it in the FAQ and online searches turned up very little except synopses. Can anyone point me toward sources or give examples which show how to: -declare a complex variable -assign the real and imaginary parts -perform the basic +,-,*,/ operations on complex numbers Thanks,
11
2430
by: jacob navia | last post by:
hi I am trying to use the complex data type. Consider this code, taken from the cclib library: struct complex csqrt(Cpx z) { double r; r=sqrt(z.re*z.re+z.im*z.im); r=sqrt(ldexp(r+fabs(z.re),-1));
9
9950
by: void main | last post by:
I'm rather new to complex numbers in C and was wondering, how do I initialize a complex variable properly if the imaginary part is 0. I tried -------- #include <complex.h> float complex c = 1.0f; --------
4
4590
by: Reshmi | last post by:
Hi, I have this C code which does complex number arithmetic. When I try to write a similar file for C++, it says that "creal’ was not declared in this scope". Can anyone give a better idea to write it using "complex.h", other than using own data structures? #include <stdio.h> #include <complex.h>
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.