473,231 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

<complex.h>

Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 9 '06 #1
17 3681
On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.

Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
You could try googling "C Standard Draft" to get a copy of the
latest draft (because it's free), or you could actually buy a
copy of C99. That'll give you all you need, although it will
likely be interspersed with a /lot/ of stuff you don't need.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 9 '06 #2
"Julian V. Noble" <jv*@virginia.eduwrites:
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
Buy a copy of C99 as a PDF. It is $30 from webstore.ansi.org.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield
Jul 9 '06 #3

"Julian V. Noble" <jv*@virginia.eduwrote
Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.

Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
Get real.
What do you expect complex.h and the library to contain?

--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
Jul 9 '06 #4
"Julian V. Noble" <jv*@virginia.eduwrote in message
news:e8**********@murdoch.acc.Virginia.EDU...
Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.

Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
http://www.dinkumware.com/manuals/?m...=complex2.html

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 9 '06 #5
Julian V. Noble wrote:
Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.

Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
There's no such thing as a standard listing for any standard header. For one
thing, headers are not even required to be text files, they could be
integrated into the compiler.

Instead, the standard describes headers in terms of what they must provide
and what effect including them has on the program. In my copy of the draft
standard (N1124, google for it) <complex.his described in section 7.3.

You could try to use the <complex.hfrom a compiler that supports C99 and
strip out all the compiler-specific bits, but I don't know of a C99
compliant <complex.himplementation. GCC for one does not qualify.

Personally I'd read section 7.3 of the standard and summarize that. It's
likely that not all bits will be relevant.

S.
Jul 9 '06 #6
Malcolm wrote:
"Julian V. Noble" <jv*@virginia.eduwrote
>Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
>>10K hits.
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
Get real.
^^^^^^^^
Love the manners on this group!
What do you expect complex.h and the library to contain?
Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhere cabs is done naively as

cabs(z=x+iy) = sqrt(x*x+y*y)

and this is liable to overflow when, say, x is bigger in magnitude
than the square root of the largest representable double. Not too
smart. Goldberg describes how to do it correctly and I can't imagine
why someone making a library would not follow that method.

The complex log and related functions have implicit decisions about
where the branch line is located. For example, in the version I found
(which I do not know is a Standard version--if there is one!) the
imaginary part of the log is given as atan2(x,y). This is defined
with a range -\pi to +\pi so that the branch line for the complex log
is the negative real axis, x = 0 to -\infty. This is a perfectly
acceptable choice, but not the only possible one. If a programmer
is expecting the range to be 0 to 2\pi he will have a hard-to-find
bug.

So what I was hoping to find was enough information that I could
supply caveats in my article without raising the hackles of the C
community.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 9 '06 #7
Ben Pfaff wrote:
"Julian V. Noble" <jv*@virginia.eduwrites:
>Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.

Buy a copy of C99 as a PDF. It is $30 from webstore.ansi.org.
Thanks, but this is a one-shot, I will never have another use
for it, and no one is going to reimburse me.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 9 '06 #8
In article <e8**********@murdoch.acc.Virginia.EDU>,
Julian V. Noble <jv*@virginia.eduwrote:
>Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhere cabs is done naively as

cabs(z=x+iy) = sqrt(x*x+y*y)
Section 7.3.4 of the C99 Standard addresses exactly this issue.
It implies, and I paraphrase, that the implementation may have
its own clever way of computing cabs, however you can tell it
to use the formula the you have cited using a preprocessor
switch as in:

#include <complex.h>
#pragma STDC CX_LIMITED_RANGE on_or_off_switch

The default value of the switch is off. Chances are that
the formula that you found in complex.h is guarded by a
conditional test of CX_LIMITED_RANGE.
>The complex log and related functions have implicit decisions about
where the branch line is located.
The C99 Standard is explicit about the location of branch cuts.
For instance for clog it says the branch cut is along the
negative real axis. An implementation which puts the cut anywhere
else is not standard-compliant.

For further details, see the C99 Standard. You may find a printed
copy in your library. See:

http://tinyurl.com/ns9o5

--
Rouben Rostamian
Jul 9 '06 #9
Andrew Poelstra wrote:
On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
>Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
>>10K hits.
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.

You could try googling "C Standard Draft" to get a copy of the
latest draft (because it's free), or you could actually buy a
copy of C99. That'll give you all you need, although it will
likely be interspersed with a /lot/ of stuff you don't need.
Thanks a lot. This was very helpful. Actually I Googled C99 Standard
Draft and got WG14N1124, a draft of 2005-05-06. It is evidently
aware of the problems of overflow and branch cut location that I
cite elsewhere in this thread. Sadly, the implementer(s) of the
versions of <complex.hthat I have seen so far have not seemed
to keep the Standard's advice in mind.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 9 '06 #10
Julian V. Noble wrote:
Malcolm wrote:
>
Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhere cabs is done naively as

cabs(z=x+iy) = sqrt(x*x+y*y)

and this is liable to overflow when, say, x is bigger in magnitude
than the square root of the largest representable double. Not too
smart. Goldberg describes how to do it correctly and I can't imagine
why someone making a library would not follow that method.
That is reasonable if it is done with promotion to the next wider
floating point format, after checking that format includes increased
exponent range, all possible at compile time. The formats were designed
specifically for such purposes. Some platforms would do it implicitly,
without any provision in source code. Evidently, then, the best
implementations are implementation dependent.
If you know the only implementation which is acceptable to you, why are
you asking for advice?
Jul 9 '06 #11
On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
Andrew Poelstra wrote:
>On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
>>Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.

You could try googling "C Standard Draft" to get a copy of the
latest draft (because it's free), or you could actually buy a
copy of C99. That'll give you all you need, although it will
likely be interspersed with a /lot/ of stuff you don't need.

Thanks a lot. This was very helpful. Actually I Googled C99 Standard
Draft and got WG14N1124, a draft of 2005-05-06. It is evidently
aware of the problems of overflow and branch cut location that I
cite elsewhere in this thread. Sadly, the implementer(s) of the
versions of <complex.hthat I have seen so far have not seemed
to keep the Standard's advice in mind.
It is true that there are very few standard C99 implementations out
there. I believe that the default compiler from Solaris is compliant,
as is the Coneau compiler.

There are a few others, which I can't think of at the moment.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 9 '06 #12
On 2006-07-09, Andrew Poelstra <ap*******@localhost.localdomainwrote:
On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
>Andrew Poelstra wrote:
>>On 2006-07-09, Julian V. Noble <jv*@virginia.eduwrote:
Dear C Mavens,

I am writing a Computing Prescription for CiSE on complex
arithmetic. I would like to be sure that I do not include
any gaffes about C99--especially about what is in the header
file <complex.h. I have Googled <complex.hand got about
177K hits, which I obviously do not wish to go through one
at a time. I also tried "<complex.hsource" but still got
10K hits.
Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
You could try googling "C Standard Draft" to get a copy of the
latest draft (because it's free), or you could actually buy a
copy of C99. That'll give you all you need, although it will
likely be interspersed with a /lot/ of stuff you don't need.

Thanks a lot. This was very helpful. Actually I Googled C99 Standard
Draft and got WG14N1124, a draft of 2005-05-06. It is evidently
aware of the problems of overflow and branch cut location that I
cite elsewhere in this thread. Sadly, the implementer(s) of the
versions of <complex.hthat I have seen so far have not seemed
to keep the Standard's advice in mind.

It is true that there are very few standard C99 implementations out
there. I believe that the default compiler from Solaris is compliant,
as is the Coneau compiler.

There are a few others, which I can't think of at the moment.
Oops! I meant "Comeau" compiler.

--
Andrew Poelstra <http://www.wpsoftware.net/projects/>
To email me, use "apoelstra" at the above domain.
"You people hate mathematics." -- James Harris
Jul 9 '06 #13
"Julian V. Noble" <jv*@virginia.eduwrites:
Ben Pfaff wrote:
>"Julian V. Noble" <jv*@virginia.eduwrites:
>>Does anyone know where I can get a complete, definitive and
(more-or-less) standard listing of <complex.h? Thanks for
any URLs.
Buy a copy of C99 as a PDF. It is $30 from webstore.ansi.org.

Thanks, but this is a one-shot, I will never have another use
for it, and no one is going to reimburse me.
N1124 is probably better for your purposes anyway. It includes all of
C99 with two Technical Corrigenda merged in and marked with change
bars.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 9 '06 #14
Tim Prince wrote:
Julian V. Noble wrote:
>Malcolm wrote:

>>
Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhere cabs is done naively as

cabs(z=x+iy) = sqrt(x*x+y*y)

and this is liable to overflow when, say, x is bigger in magnitude
than the square root of the largest representable double. Not too
smart. Goldberg describes how to do it correctly and I can't imagine
why someone making a library would not follow that method.
That is reasonable if it is done with promotion to the next wider
floating point format, after checking that format includes increased
exponent range, all possible at compile time. The formats were designed
specifically for such purposes. Some platforms would do it implicitly,
without any provision in source code. Evidently, then, the best
implementations are implementation dependent.
If you know the only implementation which is acceptable to you, why are
you asking for advice?
Wasn't asking for advice. Was asking for source for #include file. So
I could explain pitfalls of complex libraries to people who might not
be aware of them. Was also not singling out C, I will be looking also
at Python.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 10 '06 #15
Rouben Rostamian wrote:
In article <e8**********@murdoch.acc.Virginia.EDU>,
Julian V. Noble <jv*@virginia.eduwrote:
>Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhere cabs is done naively as

cabs(z=x+iy) = sqrt(x*x+y*y)

Section 7.3.4 of the C99 Standard addresses exactly this issue.
It implies, and I paraphrase, that the implementation may have
its own clever way of computing cabs, however you can tell it
to use the formula the you have cited using a preprocessor
switch as in:

#include <complex.h>
#pragma STDC CX_LIMITED_RANGE on_or_off_switch

The default value of the switch is off. Chances are that
the formula that you found in complex.h is guarded by a
conditional test of CX_LIMITED_RANGE.
>The complex log and related functions have implicit decisions about
where the branch line is located.

The C99 Standard is explicit about the location of branch cuts.
For instance for clog it says the branch cut is along the
negative real axis. An implementation which puts the cut anywhere
else is not standard-compliant.
Yes it is explicit. I found a draft version eventually after a kind
soul here steered me to it. The point is, one must _know_ where the
library puts the branch cuts. It is not inherently obvious to someone
who just writes a program. And different languages may make different
choices--AFIK there is no overall standard for this equivalent to
IEEE 754 for binary floating point operations.
For further details, see the C99 Standard. You may find a printed
copy in your library. See:

http://tinyurl.com/ns9o5
Thanks for the help.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
Jul 10 '06 #16
"Julian V. Noble" <jv*@virginia.eduwrites:
[...]
Wasn't asking for advice. Was asking for source for #include file. So
I could explain pitfalls of complex libraries to people who might not
be aware of them. Was also not singling out C, I will be looking also
at Python.
Are you looking for the standard's definition of what's required to be
in <complex.h>, or are you looking for the actual contents of the
header?

A standard header for a given implementation can, and often does,
contain all sorts of implementation-specific stuff. Usually a
programmer shouldn't care about the details. (An example of this is
the definition of type FILE in <stdio.h>.)

The description in the standard, on the other hand, establishes a
contract between the implementer and the programmer.

(A minor point: the standard headers aren't necessarily implemented as
files; they can be built into the compiler or stored in some other
form.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 10 '06 #17
"Julian V. Noble" <jv*@virginia.eduwrote in message
news:e8**********@murdoch.acc.Virginia.EDU...
Wasn't asking for advice. Was asking for source for #include file. So
I could explain pitfalls of complex libraries to people who might not
be aware of them. Was also not singling out C, I will be looking also
at Python.
Well, here's some free advice anyway. You won't find the worst problems
presented in the header file. Yes, some incredibly naive implementations
will define cabs as the inline you describe, but the real issues with
complex arithmetic are:

-- avoiding intermediate overflows

-- computing accurate results in sensitive regions, such as near
zeros

-- getting all the Inf and NaN cases right

The branch cuts tend to take care of themselves, as most implementers
use the same old approximations that Fortran has relied on for half a
century.

Now that our new product line has been released, we'll be adding our
comparative analysis of C libraries over the coming weeks. You'll find
that complex math libraries have some surprising soft spots (like clog
near the unit circle) which tend to be of more practical importance
than bogus overflows on cabs calls.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 10 '06 #18

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

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
2
by: Peng Yu | last post by:
http://www.digitalmars.com/rtl/complex.html The above the specification of complex.h, but it seem that g++(3.3) hasn't fully support it yet. I wonder where I can find the specifications of...
7
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...
2
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
3
by: Klaas Vantournhout | last post by:
Hi, I am using CLAPACK to do lots of matrix operations, but this is done on complex matrices. There I also need to work with normal complex operators, I use also the standard complex library. ...
3
by: J.M. | last post by:
I have data in a double array of length 2N, which actually represents complex numbers with real and imaginary parts interlaced. In other words, elements in this array with even indices represents...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
5
by: jeremit0 | last post by:
I'm trying to sort a vector<complex<double and can't figure it out. I recognize the problem is that there isn't a default operator< for complex data types. I have written my own operator and can...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.