🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Wayne Hayes Tue, 26 Nov 1996 00:00
No warnings when passing complex to real functions
#6093
Author: Wayne Hayes
Date: Tue, 26 Nov 1996 00:00
22 lines
1005 bytes
This should fail with an error; or at the very least, print a warning:

$ cat foo.c
#include <stdio.h>
#include <math.h>

int main()
{
	__complex__ z = 1.0i;

	printf ("exp(%gi) = %g + %gi\n", __imag__ z,
		__real__ exp(z), __imag__ exp(z));

	return 0;
}
$ gcc -Wall foo.c -lm
$ ./a.out
exp(1i) = 1 + 0i

It appears that exp() (and sin()) just take the real part of it's argument,
ignoring the imaginary part.
Re: No warnings when passing complex to real functions
#6095
Author: Andreas Schwab
Date: Wed, 27 Nov 1996 00:00
29 lines
1408 bytes
Wayne Hayes <wayne@cs.toronto.edu> writes:

|> This should fail with an error; or at the very least, print a warning:
|> $ cat foo.c
|> #include <stdio.h>
|> #include <math.h>

|> int main()
|> {
|> 	__complex__ z = 1.0i;

|> 	printf ("exp(%gi) = %g + %gi\n", __imag__ z,
|> 		__real__ exp(z), __imag__ exp(z));

|> 	return 0;
|> }
|> $ gcc -Wall foo.c -lm
|> $ ./a.out
|> exp(1i) = 1 + 0i

|> It appears that exp() (and sin()) just take the real part of it's argument,
|> ignoring the imaginary part.

Does <math.h> declare *prototypes* for exp() and sin()?  Without them gcc
cannot help you here.
-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads