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.00000i
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32 25 9408
"jacob navia" <ja***@nospam.comwrote 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.00000i
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.
In article <12**************@news.newsgroups.com>, "Gerry Ford" <in*****@invalid.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.
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
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
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...
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
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
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...)
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.00000i
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",real(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...)
jacob navia <ja***@nospam.comwrites:
The C99 standard forgot to define the printf equivalent for complex numbers
I doubt that they forgot; they probably just didn't feel it was
necessary. In my opinion, they were right.
Since I am revising the lcc-win implementation of complex numbers
I decided to fill this hole with
"Z"
Do you have a similar extension for scanf?
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.00000i
I see no problem with this extension in terms of conformance to the
standard. Though I don't see any particular need for a special format
for complex numbers, I wouldn't object if such a format were added to
a future version of the standard.
However, if I were a user of lcc-win, I probably wouldn't use it in my
own code, for several reasons.
First, it is of course an extension. Unless my code already depends
on other lcc-win extensions, I'd rather not limit its portability for
the sake of a minor convenience.
Second, it's inflexible; it imposes one of two output representations
for complex numbers. If I want to print "2+3*I", I can write:
printf("%g+%g*I\n", creal(m), cimag(m));
If I want to print "2 + 3i", of course, I can write:
printf("%g + %gi\n", creal(m), cimag(m));
which your extension doesn't support, but the standard already does.
In effect, I tend to think of a complex number as a number (usually)
for purposes of arithmetic, but as a composite structure for purposes
of I/O. Perhaps that's just me.
Finally Fortran has supported complex numbers, and I/O on them, since
dinosaurs walked the Earth. The result of printing 2+3*I in Fortran
would be "(2.,3.)" (at least by default using g77; I don't know
Fortran well enough to know whether that's standard). That form is
also valid in Fortran source as a complex literal (insert previous
disclaimer here).
Note that a parenthesized format might make things easier for a
corresponding scanf extension.
This is not to say that your extension is a bad idea, merely that I
personally don't find it to be a sufficiently good idea to pique my
interest. (And yet here I am writing about it at some length.)
Or, as "Gerry Ford" might put it, "Bertha termite prefecture
psychopomp inhabit dovetail statuette virus superlative deposition."
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
jacob navia wrote:
>
The C99 standard forgot to define the printf equivalent for
complex numbers
I don't believe so. Formatting of such dumps is easily done by
selecting the real and imaginary portions, and using the existing
printf operations to format them. Why standardize something that
will not be used and is unnecessary?
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
In article <87************@kvetch.smov.org>,
Keith Thompson <ks***@mib.orgwrote:
>Second, it's inflexible; it imposes one of two output representations for complex numbers. If I want to print "2+3*I", I can write:
printf("%g+%g*I\n", creal(m), cimag(m));
>If I want to print "2 + 3i", of course, I can write:
printf("%g + %gi\n", creal(m), cimag(m));
>which your extension doesn't support, but the standard already does.
Then there is engineering, in which the imaginary constant is
usually represented as 'j' instead of 'i' or 'I'.
--
"Style is instinctive and few achieve it in a notable degree. Its
development is not hastened by instruction. It comes or it doesn't.
It will take care of itself." -- Walter J. Phillips
On Fri, 29 Feb 2008 16:08:59 +0000, Nelu wrote:
<snip>
printf ("%f+%f*I\n",real(m),imag(m)) is not that big of an effort, is
That's probably creal and cimag. I think the real/imag forms are only
available in C++.
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
In article <47***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>jacob navia wrote:
>The C99 standard forgot to define the printf equivalent for complex numbers
>I don't believe so. Formatting of such dumps is easily done by selecting the real and imaginary portions, and using the existing printf operations to format them. Why standardize something that will not be used and is unnecessary?
Because it gives an opportunity to demonstrate the incomparible
beauty of operator overloading??
--
"To all, to each! a fair good-night,
And pleasing dreams, and slumbers light" -- Sir Walter Scott
Walter Roberson wrote:
In article <47***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>jacob navia wrote:
>>The C99 standard forgot to define the printf equivalent for complex numbers
>I don't believe so. Formatting of such dumps is easily done by selecting the real and imaginary portions, and using the existing printf operations to format them. Why standardize something that will not be used and is unnecessary?
Because it gives an opportunity to demonstrate the incomparible
beauty of operator overloading??
Operator overloading in printf?
Funny how much nonsense you can say. Are you paid by the nonsense line?
Or you do it for free as a hobby?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique http://www.cs.virginia.edu/~lcc-win32
"jacob navia" <ja***@nospam.comwrote 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
printf("%Zg\n",m);
2+3*I
printf("%#Zg\n",m);
2.00000+3.00000i
As has been mentioned, it may not be flexible enough for all situations, but
may be convenient sometimes.
But inventing new printf formats is fun; how about the following for
printing arrays and blocks of data:
int a[] = {10,20,30,40,50,60};
printf(" (%A,%d)\n",a,6);
will print: (10,20,30,40,50,60)
%A means array print, the parameter should point to the data. An extra
int/size_t parameter is how many values to print. The format of each element
follows (%d). The text between %A and %d is separator chars. Maybe %10A for
10 elems per line.
Might get more use than %Z anyway.
--
Bart
Bartc wrote:
But inventing new printf formats is fun; how about the following for
printing arrays and blocks of data:
int a[] = {10,20,30,40,50,60};
printf(" (%A,%d)\n",a,6);
will print: (10,20,30,40,50,60)
%A means array print, the parameter should point to the data. An extra
int/size_t parameter is how many values to print. The format of each element
follows (%d). The text between %A and %d is separator chars. Maybe %10A for
10 elems per line.
Might get more use than %Z anyway.
Cool! How about :
printf("%f",a[i=0; i<6; i++]);
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA http://www.iedu.com/DeSoto/Stirling/
Bartc wrote:
But inventing new printf formats is fun; how about the following for
printing arrays and blocks of data:
int a[] = {10,20,30,40,50,60};
printf(" (%A,%d)\n",a,6);
will print: (10,20,30,40,50,60)
%A means array print,
You'll need to choose some other specifier. "%A" already is defined for
signed hexadecimal floating-point conversion.
Morris Dovey <mr*****@iedu.comwrites:
Bartc wrote:
Cool! How about:
printf("%f",a[i=0; i<6; i++]);
Heh, I just had to try that thinking I missed a new feature of C99 ;-)
--
burton
Morris Dovey wrote:
Bartc wrote:
>But inventing new printf formats is fun; how about the following for printing arrays and blocks of data:
int a[] = {10,20,30,40,50,60};
printf(" (%A,%d)\n",a,6);
will print: (10,20,30,40,50,60)
%A means array print, the parameter should point to the data. An extra int/size_t parameter is how many values to print. The format of each element follows (%d). The text between %A and %d is separator chars. Maybe %10A for 10 elems per line.
Might get more use than %Z anyway.
Cool! How about:
printf("%f",a[i=0; i<6; i++]);
Ahhh, that conjures up memories, that does. It was hard
work shovelling punched cards into the computer's firebox
(steam-powered computers in those days; had to keep up the
pressure if you wanted any accuracy), but back then I was
young, and strong, and stupid in that particular way that
expressed itself in ever more ingenious combinations of WRITE
and FORMAT. Little programming languages embedded inside the
larger one, seeming at times almost Turing-complete.
The old memories fade and blur, but never quite die ...
-- Er*********@sun.com bu*****************@AM.gmail.com wrote:
>
Morris Dovey <mr*****@iedu.comwrites:
printf("%f ",a[i=0; i<6; i++]);
Heh, I just had to try that thinking I missed a new feature of C99 ;-)
I wish. It was just an "implied DO loop" adapted from FORTRAN IV
(and later) READ/WRITE statements - wishful thinking on my part.
--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA http://www.iedu.com/DeSoto/Stirling/
Morris Dovey <mr*****@iedu.comwrites: bu*****************@AM.gmail.com wrote:
>> Morris Dovey <mr*****@iedu.comwrites:
printf("%f ",a[i=0; i<6; i++]);
Heh, I just had to try that thinking I missed a new feature of C99 ;-)
I wish. It was just an "implied DO loop" adapted from FORTRAN IV
(and later) READ/WRITE statements - wishful thinking on my part.
Wow, that's an interesting syntactic construct for a complied
language. I haven't looked at FORTRAN at all, but that's pretty
interesting that they have that feature. I was looking closer at the
C version you wrote and was wondering if it even could be implemented
in your typical C compiler...
/me goes off to read more about FORTRAN...
--
burton
In article <fq**********@aioe.org>, jacob navia <ja***@nospam.orgwrote:
>Walter Roberson wrote:
>Because it gives an opportunity to demonstrate the incomparible beauty of operator overloading??
>Operator overloading in printf?
Why -not- operator overloading in printf() ? Other than, of course,
the matter of whether printf() qualifies as an "operator"
or not.
Urrr, you do allow operator overloading of varadic functions,
don't you?
>Funny how much nonsense you can say. Are you paid by the nonsense line? Or you do it for free as a hobby?
Why, the union contract sets out a monthly quota of course.
--
"Prevention is the daughter of intelligence."
-- Sir Walter Raleigh
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.caschreef in bericht
news:fq**********@canopus.cc.umanitoba.ca...
In article <87************@kvetch.smov.org>,
Keith Thompson <ks***@mib.orgwrote:
>>Second, it's inflexible; it imposes one of two output representations for complex numbers. If I want to print "2+3*I", I can write:
> printf("%g+%g*I\n", creal(m), cimag(m));
>>If I want to print "2 + 3i", of course, I can write:
> printf("%g + %gi\n", creal(m), cimag(m));
>>which your extension doesn't support, but the standard already does.
Then there is engineering, in which the imaginary constant is
usually represented as 'j' instead of 'i' or 'I'.
I guess that is why it isnt put in and it wasnt an oversight.
It is interesting to see that in C++ you can output complex numbers with
cout, although I dont know if thats standard.
std::complex<doublec(5., 6.);
std::cout << c << std::endl;
this prints: "(5,6)" on my machine
If thats standard I would say use that same mechanism in lccwin32 too and
also in the C standard if it ever gets adopted. More consistent this way
--
"Style is instinctive and few achieve it in a notable degree. Its
development is not hastened by instruction. It comes or it doesn't.
It will take care of itself." -- Walter J. Phillips
"We're sorry. You have reached an imaginary number. Please rotate
your phone 90 degrees and try again." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: gc |
last post by:
Hi,
Why didn't the committee propose a new type for complex numbers with
integer components?
thanks,
gc
|
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
|
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...
|
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...
|
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...
|
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);...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |