473,888 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

_Complex constant

Is there any way to create a constant of type double _Complex without
including <complex.h>?

Why _Complex_I is a macro an not an implementation-defined constant?

Thanks.

a+, ld.
Nov 23 '06 #1
22 5993
Laurent Deniau wrote:
Is there any way to create a constant of type double _Complex without
including <complex.h>?
>From the C99 rationale:
"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.
Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Nov 23 '06 #2
Harald van Dijk wrote:
Laurent Deniau wrote:
>>Is there any way to create a constant of type double _Complex without
including <complex.h>?

>>From the C99 rationale:
"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.

>>Why _Complex_I is a macro an not an implementation-defined constant?


Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */
Right. By specifying 'implementation-defined constant' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Compl ex_I for example.

My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

Thanks.

a+, ld.

Nov 23 '06 #3
Laurent Deniau wrote:
Harald van Dijk wrote:
Laurent Deniau wrote:
>Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

Right. By specifying 'implementation-defined constant' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Compl ex_I for example.
Well, that's basically what _Complex_I is required to do already. (Not
explicitly by the standard, but I can't imagine how an implementation
would support it otherwise.) As you show below, GCC uses a compiler
constant itself.
My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?
That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.

Nov 23 '06 #4
"Harald van Dijk" <tr*****@gmail. comwrites:
Laurent Deniau wrote:
[...]
>Why _Complex_I is a macro an not an implementation-defined constant?

Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */
Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.

--
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.
Nov 23 '06 #5
Keith Thompson wrote:
"Harald van Dijk" <tr*****@gmail. comwrites:
Laurent Deniau wrote:
[...]
Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.
Right, sorry, I (incorrectly) thought a different meaning of "constant"
was used.

Nov 23 '06 #6
"Harald van Dijk" <tr*****@gmail. comwrites:
Keith Thompson wrote:
>"Harald van Dijk" <tr*****@gmail. comwrites:
Laurent Deniau wrote:
[...]
>Why _Complex_I is a macro an not an implementation-defined constant?

Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.

Right, sorry, I (incorrectly) thought a different meaning of "constant"
was used.
That's a very easy mistake to make, since "const" and "constant" mean
two very different things in C.

--
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.
Nov 23 '06 #7
Harald van Dijk wrote:
Laurent Deniau wrote:
>>It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?


That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.
It brings me to another question. I do a lot of calculation with complex
numbers (making the above warning painful unless I declare my own global
const-qualified _Complex_I) and up to now I was using my own complex
number lib (or gsl lib sometimes) mainly because I wanted the principal
branch of some functions to be compliant with matlab results. I am
planning to move my code to C99 _Complex, but is it widely supported and
conform to the standard by actual compilers? Do you know where I could
find any paper, link or document about comparison of compilers
compiliance to C99, including complex number? Or do think that it would
be wiser to stay with lib gsl for example?

Thanks,

a+, ld.

Nov 24 '06 #8
Laurent Deniau wrote:
Harald van Dijk wrote:
Laurent Deniau wrote:
>It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.

It brings me to another question. I do a lot of calculation with complex
numbers (making the above warning painful unless I declare my own global
const-qualified _Complex_I) and up to now I was using my own complex
number lib (or gsl lib sometimes) mainly because I wanted the principal
branch of some functions to be compliant with matlab results. I am
planning to move my code to C99 _Complex, but is it widely supported and
conform to the standard by actual compilers?
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).
Do you know where I could
find any paper, link or document about comparison of compilers
compiliance to C99, including complex number?
No idea, sorry.
Or do think that it would
be wiser to stay with lib gsl for example?
That depends on your needs. I don't know what sort of code you've
written, but another possibility is to support both, and use only one
(with C99 support to be detected by your build process). This means
your code can be portable to C90 implementations , yet you don't
introduce needless incompatibiliti es between your own lib and C99's
standard library.

Nov 24 '06 #9
Harald van D?k wrote:
>
.... snip ...
>
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).
On the contrary, without -ansi -pedantic gcc isn't a C compiler.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Nov 24 '06 #10

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

Similar topics

25
2600
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python language. There are some workarounds available, for example the const-module. To me, this looks quite cumbersome and very unintuitive. For the interpreter, in the efficiency-wise, I just cannot tell.
3
2357
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5 Constants'.
25
5741
by: galapogos | last post by:
Hi, I'm trying to compare an array of unsigned chars(basically just data without any context) with a constant, and I'm not sure how to do that. Say my array is array and I want to compare it with the constant 0x00010203040506070809 where array == 0x00, array == 0x01, etc. How do I do that. Obviously I can't use memcmp() with the 0x00010203040506070809 since the compiler will use that constant as an address and give me a segfault. Other...
21
4229
by: Lane Straatman | last post by:
#include <stdio.h> #include <stdlib.h> #include <complex.h> int main(void) { _Complex z1, z2, z3; z1 = .4 + .7i; z2 = pow(z1, 2); z3 = z1 * z1; printf("%f, %f \n", z1);
33
5584
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is practically a red-black tree where insert/delete takes O(lg n) time. Or are there some other explanation for this complexity?
18
1941
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
0
10778
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
10886
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,...
0
9597
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 projectplanning, coding, testing, and deploymentwithout 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
7990
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
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
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
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
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.