Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!axion!planet!prk From: prk@planet.bt.co.uk (Peter Knight) Newsgroups: comp.lang.c Subject: Re: # to the nth power Message-ID: Date: 2 Nov 90 15:24:43 GMT References: <90305.005050CJH101@psuvm.psu.edu> Sender: usenet@planet.bt.co.uk (Usenet News Manager) Organization: RT743, BT Research Labs, Martlesham Heath, Ipswich, UK. Lines: 30 CJH101@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