As a Mathematician I would like:

Don Clugston dac at nospam.com.au
Fri Jun 29 21:56:27 PDT 2007


Stephen Montgomery-Smith wrote:
> Don Clugston wrote:
>> Stephen Montgomery-Smith wrote:
>>> If I had two changes I would make to the C programming language, it is
>>>
>>> 1. Put in an exponentiation operator, a^b or a**b, so that 2**3 is 8. 
>>> For a numerics programmer this would be really useful. This is one 
>>> way that Fortran really scores over C. I know that there is the pow 
>>> function in C, but it always treats the power as a float or double, 
>>> where if the power is an integer it should really work differently.
>> Actually pow() does work differently for integers.
>>> Also the optimization should be able to do clever things with a^2 
>>> (i.e. write it as inline code a*a).
> 
> If I write a = pow(x,5.0), would a typical modern compiler produce 
> inline code something like
> b=x*x;
> a=b*b*x?
> If this is so, that is really neat!!!
Some compilers do have pow() as an intrinsic for integer powers, so they do 
exactly that. I don't think DMD or GDC do, though. However, in the library code, 
integer powers are done by repeated multiplication, rather than via exp and log.
When D gets macros, constant integer powers will indeed become inline multiplies.



More information about the Digitalmars-d mailing list