bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: some questions about the complex datatype


From: Andreas Jaeger
Subject: Re: some questions about the complex datatype
Date: Fri, 18 Jan 2002 09:44:41 +0100
User-agent: Gnus/5.090005 (Oort Gnus v0.05) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux)

Peter Jay Salzman <address@hidden> writes:

> hi there,
>
> the libc page mentioned that questions can be forwarded to this list.
> if there's a better place to ask questions, please advise me where to
> go.  also, is there a way to subscribe to this list?
>
>
> a couple of questions about the complex datatype:
>
> how can i get gdb to print out the value of a long double complex?  i
> tried everything that was obvious to me.  for a long double complex a:
>
>    (gdb) ptype a
>    type = complex long double
>    (gdb) p a
>    $2 = Invalid C/C++ type code 20 in symbol table.
>    (gdb) p creall(a)
>    $3 = 1
>    (gdb) p cimagl(a)
>    $4 = 1
>    (gdb) printf "%Le, %Le", a
>    Wrong number of arguments for specified format-string
>    (gdb) printf "%Le", a
>    Value can't be converted to integer.

Create your own subroutine and call it.  
> at this point, i'm stumped.  what's the magic here?
>
>
> also, if Psi[i] is a long double complex, i'm a little confused how to
> print |Psi[i]|^2.  the obvious thing from a math standpoint would be 
>
>    fprintf(fp, "%Le", conj(Psi[i]) * Psi[i]);
>
> which doesn't work.  gcc complains that %Le is for long doubles and
> conj(Psi[i]) * Psi[i]) is long double complex.   the abs() function
> takes doubles.  and the info pages don't mention anything about a
> cabsl() function (which would be really nice).

glibc has fabsl and also cabsl, it's in the manual, section "Absolute
Value"

>
> how can i print the real number conj(z) * z to a file?   do i really
> have to resort to something really horrible like:
>
>    fprintf(fp, "%Le", sqrtl( creal(Psi[i]) * Psi[i]) creal(Psi[i]) * Psi[i])
>       + cimagl(Psi[i]) * Psi[i]) cimagl(Psi[i]) * Psi[i]) ) );
>
> (i'm staying away from pow() for speed considerations).

I didn't check the math but fprintf and converting it yourself is the
right thing.

Note that complex is just a struct with some magic added and not like
e.g. long double.  complex has no special output and input functions.

Andreas

> thanks!   :)
>
> pete
>
> ps - sorry if this is gcc related and not libc related.  it's my
> understanding that these questions are library related, not compiler
> related.  but the truth is i'm a physicist, not a CS major...

-- 
 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]