473,406 Members | 2,208 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,406 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 3696
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.