www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.math.pow

reply "Saaa" <empty needmail.com> writes:
?
main.d(118): function std.math.pow called with argument types:
 (double,uint)
matches both:
 std.math.pow(real,uint)
and:
 std.math.pow(real,real)

Also, I use pow(x,2U). Is this the correct function to use or is there a 
dedicated x*x function? 
Oct 26 2008
parent reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
Saaa wrote:

 ?
 main.d(118): function std.math.pow called with argument types:
  (double,uint)
 matches both:
  std.math.pow(real,uint)
 and:
  std.math.pow(real,real)
 
 Also, I use pow(x,2U). Is this the correct function to use or is there a
 dedicated x*x function?
you can solve that by casting x into real before the call pow(cast(real)x,2U); but in this case why not just simply write x*x? personally I think thats both clearer and more efficient.
Oct 26 2008
parent reply "Saaa" <empty needmail.com> writes:
"Johan Granberg" <lijat.meREM OVEgmail.com> wrote in message 
news:ge1lob$1b2i$1 digitalmars.com...
 Saaa wrote:

 ?
 main.d(118): function std.math.pow called with argument types:
  (double,uint)
 matches both:
  std.math.pow(real,uint)
 and:
  std.math.pow(real,real)

 Also, I use pow(x,2U). Is this the correct function to use or is there a
 dedicated x*x function?
you can solve that by casting x into real before the call pow(cast(real)x,2U);
Yes, but why is this necessary? Isn't there a preference to more matching arguments if all arguments could be implicitly converted?
 but in this case why not just simply write x*x? personally I think thats 
 both clearer and more efficient.
Well, x is a lot bigger than just x :)
Oct 26 2008
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Oct 26, 2008 at 8:47 AM, Saaa <empty needmail.com> wrote:
 you can solve that by casting x into real before the call
 pow(cast(real)x,2U);
Yes, but why is this necessary? Isn't there a preference to more matching arguments if all arguments could be implicitly converted?
No. See the section on function overloading on this page: http://www.digitalmars.com/d/1.0/function.html So for pow(x, 2u), where x is a double, the match level for both (real, uint) and (real, real) is "match with implicit conversions." Therefore, it's an error.
Oct 26 2008
parent "Saaa" <empty needmail.com> writes:
Thanks :)

 No.  See the section on function overloading on this page:
 http://www.digitalmars.com/d/1.0/function.html

 So for pow(x, 2u), where x is a double, the match level for both
 (real, uint) and (real, real) is "match with implicit conversions."
 Therefore, it's an error. 
Oct 26 2008