# to the nth power

Peter Knight prk at planet.bt.co.uk
Sat Nov 3 02:24:43 AEST 1990


CJH101 at psuvm.psu.edu (Carl J. Hixon) writes:

>I appologize for bothering you computer wizards with such an elementary
>question but, I'm floundering.  Why am I unable to find an opperator which
>raises a number to a power. (The fortran equivalent of x**n)  Is there such
>an opporator or do I need to write my own function?  It seems like a terrible
>oversite to me that such a common operation was overlooked.

>Any help would be greatly appreciated!  I'm not sure I could even write the
>function, I'm currently writing my first C program ever...

>Thankyou,

>Carl

The likely offered solutions in C, involving ln()/exp() or the pow() functions
are not going to be a capable as Fortran's x**n.  These functions cannot cope
with Fortran legal operations like (-1e6)**10.  Usually, you will have to
cope with the sign yourself.  The other 'gotcha' you are going to encounter
is that doubles rather than floats have a greater range of values (!), ie


	double d;
	float f;

	d=1e300;
	f=d;		/*	This is a error on 99% of machines	*/

Peter Knight
BT Research



More information about the Comp.lang.c mailing list