Personal tools
You are here: Home Projects C++ Cfront releases Release 1.0 Source cfront lib complex exp.c
Document Actions

exp.c

by Paul McJones last modified 2007-02-02 09:32

Click here to get the file

Size 1.1 kB - File type text/x-csrc

File contents

/*#ident	"@(#)cfront:lib/complex/exp.c	1.3"*/

#include "complex.h"
#include "const.h"


complex
exp(complex z)
/*
	The complex exponentiation function: e**z, e being 2.718281828...

	In case of overflow, return ( HUGE, HUGE ).
	In case of underflow return 0.
	In case of ridiculous input to "sin" and "cos", return 0.
*/
{
	complex	answer;
	double 	radius, sin_theta, cos_theta;
	c_exception ex( "exp", z );
	int write( int , char *, unsigned int );

#define EXPGOOD	1e7

	if (z.im > EXPGOOD || z.im < -EXPGOOD)
	{
		ex.type = OVERFLOW;
		if ( !complex_error( ex ))
			errno = ERANGE;
		return( ex.retval );
	}

	if (z.re < MIN_EXPONENT)
	{
		ex.type = UNDERFLOW;
		if ( !complex_error( ex ))
			errno = ERANGE;
   		return( ex.retval );
   	}

	sin_theta = sin(z.im);
	cos_theta = cos(z.im);

	if (z.re > MAX_EXPONENT)
	{
		ex.type = OVERFLOW;
		ex.retval.re = (cos_theta > 0) ? HUGE : -HUGE;
		ex.retval.im = (sin_theta > 0) ? HUGE : -HUGE;
		if ( !complex_error( ex ))
			errno = ERANGE;
   		return( ex.retval );
    	}
	else
    		radius = exp(z.re);

	answer.re = radius * cos_theta;
	answer.im = radius * sin_theta;
	return answer;
}
« September 2014 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: