Re: Function missing for complex numbers
- From: jacob navia <jacob@xxxxxxxxxx>
- Date: Fri, 15 May 2009 20:48:41 +0200
Lew Pitcher wrote:
On May 15, 2009 11:31, in comp.std.c, jacob navia (jacob@xxxxxxxxxx) wrote:
Lew Pitcher wrote:On May 15, 2009 06:58, in comp.std.c, jacob navia (jacob@xxxxxxxxxx)Well, sorry, I forgot to explain but there is
wrote:
I am translating complex number codes from fortran and C++ into the C99Sounds like the usual state of application programming to me. When
notation.
Since this notation is not used in any significant package (that I know
of), translating other languages codes is unavoidable.
What is missing (besides several other stuff) is a function that takes
two floating point numbers and returns a complex.
porting code from one language to another, you often find language idioms
that do not have a direct translation. Part of the porting process is to
write application-level code that stands in for the source language
idiom.
C++ provides theI presume that this is your proposal: to add to the new C standard a set
constructor, what would NICE to have in C99. Fortran has
CMPLX(real,imag).
long double _Complex Complexl(long double,long double);
double _Complex Complex(double,double);
float _Complex Complexf(float,float);
of standard functions that build complex data from floatingpoint values?
If so, could you expand on the workings and external behaviour of each of
these functions? How do you see these functions working? What error
conditions will they handle (or not handle)? What do the results look
like?
(1) All those return a complex number of the corresponding type
(float, double or long double _Complex)
(2) I do not see how those functions could fail. That is why
there wasn't any error handling discussion. How could they fail?
Can you provide an example?
1) You have given us the function prototypes for three functions, and
verbally explained that each function would take "two floating point
numbers and returns a complex".
Yes, the first is the real part, the second the imaginary part.
In true C99 style we would have:
The Complex functions
---------------------
Synopsis:
#include <complex.h>
long double _Complex Complexl(long double,long double);
double _Complex Complex(double,double);
float _Complex Complexf(float,float);
Description:
The complex functions take two floating point numbers, the real part and the imaginary part of a complex number that is returned as their result. NAN and INF arguments are inserted as such. No conversions are performed.
Returns:
The Complex functions return a complex number result with the same precision as their arguments.
a) The suggested function names deviate from similarity to other standard C
functions, in that they each begin with a capital letter. For what reason
do you suggest this deviation?
The reason is obvious: the identifier "complex" is already used. Besides
the name of the type is _Complex and NOT _complex, contrary to all other
C types that are lower case. I think that it would be highly confusing for the user that the identifier Complex was used in a mixture of lower
and upper case.
b) You have not provided the algorithm that each of these functions would
use in order to accomplish the given task. With your current suggestion,
double _Complex Complex(double a, double b)
{
double _Complex c;
return c;
}
may satisfy the requirements, but would not generate the "correct"
results. So, tell us what these three functions are supposed to do, and
how they are supposed to do it.
See above
2) Each of the proposed functions accepts an argument list containing two
floatingpoint numbers (of varying precision). How will each of these
functions deal with an argument of NaN or INF?
See above
In C++ and Fortran they are used a lot, in all codes I translated.This would make easier to translate codes from C++ and Fortran intoWhen compared against the writing of new code that would use these
C.
functions, how often do you see these new functions being used for
porting code?
In other words, is code porting the only (or greatest) utility ofYes.
these functions?
Why should the standard include new functionality that is now coded only
infrequently, and only (or primarily) for the purposes of porting code to
C? You are asking C compiler implementors to add new functionality that
will hardly ever be used. You, personally, know the cost in development and
maintenance time to add such functions to a compiler; are those costs worth
it?
The new C99 notation has no code base since the standard decided not to
follow existing practice either in the "i" suffix for complex number constants, or with the "constructor" mechanism of C++ and FORTRAN.
To easy the porting from those languages those functions are useful.
Besides, they provide functionality that is difficult to achieve
using the + notation, for instance when we want to construct a complex
number with negative zeros, INF or NANs.
How about new code? Given the amount of activity around
porting or writing new "complex" code, is it worth the effort to define
and standardize these functions?
I can't tell if anyone is using C99 complex code. I have no data. I am
translating codes to test my implementation, and I suppose that other
people would need to translate complex number code from Fortran and C++,
the main languages where there is already a lot of code already
written.
not really.As it is now, the function call must be replacedIn a later post, when asked the question
C=complex(A,B) --> C = A + (I*(b)), what is quite different and
contributes to the difficulty of translating those codes.
you answer withWhat's so difficult about A + I * B?Translation is much more complicatedWhen you say "translation", are you referring to the work of the
compiler,
or your work as the compiler developer, or your work as an applicationI am translating those codes to test my implementation. Each time I find
developer?
a new package I see that complex(a,b) is used a lot, or CMPLX(a,b)
The problem with A+I*B is to make sure you have the parentheses
in the right place to avoid changing the algorithm... It is much
easier to translate a function call with another function call.
Oh, so you ask that the standard include these (likely seldomly used)
functions so that you, as an application developer, do not have to code a
small macro or helper function, the few times it becomes necessary?
You are against anything I say or propose. It is your right obviously,
but thinking that I want to spare the coding of those utterly trivial
functions is just ridiculous. If I wanted just to code those in
lcc-win, I would have done it in less time than what I am spending
answering your questions.
My objective is to have a consistent language. I think those functions
are needed in a consistent implementation of complex numbers.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.
- Follow-Ups:
- Re: Function missing for complex numbers
- From: Keith Thompson
- Re: Function missing for complex numbers
- From: Lew Pitcher
- Re: Function missing for complex numbers
- References:
- Function missing for complex numbers
- From: jacob navia
- Re: Function missing for complex numbers
- From: Lew Pitcher
- Re: Function missing for complex numbers
- From: jacob navia
- Re: Function missing for complex numbers
- From: Lew Pitcher
- Function missing for complex numbers
- Prev by Date: Re: Function missing for complex numbers
- Next by Date: Re: Function missing for complex numbers
- Previous by thread: Re: Function missing for complex numbers
- Next by thread: Re: Function missing for complex numbers
- Index(es):
Relevant Pages
|