Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 26, 2008 std.math.pow | ||||
---|---|---|---|---|
| ||||
? 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? |
October 26, 2008 Re: std.math.pow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | 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.
|
October 26, 2008 Re: std.math.pow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | "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 :) |
October 26, 2008 Re: std.math.pow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | 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. |
October 26, 2008 Re: std.math.pow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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.
|
Copyright © 1999-2021 by the D Language Foundation