Thread overview  


November 27, 2007 pow() function question  

 
I am relatively new to D. So far, I really like it. However, I need to do some power functions on integers. Is pow() the only way of performing this type of function? It seems silly to have to either use reals for integer work. This was one of my gripes with C's pow() function. I check the news archives and noticed there was talk of creating a '**' power function for integers back in 2005. I tried it but it didn't work. Michael (remove nospam if you need to get a hold of me personally) 
November 27, 2007 Re: pow() function question  

 
Posted in reply to aeschere  "aeschere" <aeschere@nospam.cryptobit.org> wrote in message news:fiheps$2m28$1@digitalmars.com... >I am relatively new to D. So far, I really like it. However, I need to > do some power functions on integers. Is pow() the only way of performing this type of function? It seems silly to have to either use reals for integer work. This was one of my gripes with C's pow() function. I check the news archives and noticed there was talk of creating a '**' power function for integers back in 2005. I tried it but it didn't work. > > Michael > (remove nospam if you need to get a hold of me personally) If you're using phobos, std.math.pow has an overload for integral exponents. Although I think it's only highly optimized for lower powers, like up to the third or fourth; anything higher and I think it uses floating point numbers. Keep in mind that floating point performance on modern processors is not exactly slow. Doing a power operation (which involves.. what, a ln? something like that) might be faster than a loop that multiplies the integers over and over. 
November 27, 2007 Re: pow() function question  

 
Posted in reply to Jarrett Billingsley  Thanks for the help. I am currently using GDC compiler. I am not sure if I am using phobos or not. I will try to see what std.math.pow gives me.
Michael
Jarrett Billingsley wrote:
> "aeschere" <aeschere@nospam.cryptobit.org> wrote in message news:fiheps$2m28$1@digitalmars.com...
>> I am relatively new to D. So far, I really like it. However, I need to do some power functions on integers. Is pow() the only way of performing this type of function? It seems silly to have to either use reals for integer work. This was one of my gripes with C's pow() function. I check the news archives and noticed there was talk of creating a '**' power function for integers back in 2005. I tried it but it didn't work.
>>
>> Michael
>> (remove nospam if you need to get a hold of me personally)
>
> If you're using phobos, std.math.pow has an overload for integral exponents. Although I think it's only highly optimized for lower powers, like up to the third or fourth; anything higher and I think it uses floating point numbers.
>
> Keep in mind that floating point performance on modern processors is not exactly slow. Doing a power operation (which involves.. what, a ln? something like that) might be faster than a loop that multiplies the integers over and over.
>
>

November 28, 2007 Re: pow() function question  

 
Posted in reply to aeschere  "aeschere" <aeschere@nospam.cryptobit.org> wrote in message news:fihkob$2vlc$1@digitalmars.com... > Thanks for the help. I am currently using GDC compiler. I am not sure if I am using phobos or not. I will try to see what std.math.pow gives me. > If you're not using Tango, you're using phobos. 
Copyright © 19992016 by the D Language Foundation