473,770 Members | 6,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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.hsour ce" 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
17 3735
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.hwhe re 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.e duwrote:
Andrew Poelstra wrote:
>On 2006-07-09, Julian V. Noble <jv*@virginia.e duwrote:
>>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.hsour ce" 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.htha t 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*******@loca lhost.localdoma inwrote:
On 2006-07-09, Julian V. Noble <jv*@virginia.e duwrote:
>Andrew Poelstra wrote:
>>On 2006-07-09, Julian V. Noble <jv*@virginia.e duwrote:
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.hsour ce" 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.htha t 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.e duwrites:
Ben Pfaff wrote:
>"Julian V. Noble" <jv*@virginia.e duwrites:
>>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.o rg.

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_Keit h) 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.hwhe re 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**********@m urdoch.acc.Virg inia.EDU>,
Julian V. Noble <jv*@virginia.e duwrote:
>Well, for one I would like to see how cabs and clog are implemented.

I have already found a <complex.hwhe re 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_RANG E on_or_off_switc h

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_RANG E.
>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.e duwrites:
[...]
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_Keit h) 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.e duwrote 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
3231
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 writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
2
10568
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 type="text/javascript"> <!]> </script> <script type="text/javascript"
2
1762
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 complex.h supported by old version g++ (say 2.95.4). Peng
7
4139
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));
2
9790
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 double() of class B is called for the member complex::operator*=(double) as expected, but not for operator*(complex, double). The effect is, that the template matching (or overload resolution)
3
3552
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. Unfortunately this one conflicts with some stuff in f2c.h needed to run CLAPACK. Examples are that f2c.h declares a variable complex that fights with everything from the standard complex header. Most errors I got rid of by dumping all the...
3
6178
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 the real part of a complex number, elements with odd indices represent the imaginary part. I actually need an array of length N of type complex<double>. Obviously, I could copy the data and destroy the first array, but this is an expensive option....
3
3382
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, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
5
6054
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 use it, but std::sort doesn't seem to find it. I have copied a very simple example below. Everything compiles just fine when the line with std::sort function is commented out, but with that line included a whole slew of errors are given like: ...
0
10232
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
10059
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...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8891
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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
5313
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...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.