On Mon, May 30, 2011 at 16:16, Matthew Knepley <knepley at gmail.com> wrote:

> On Sun, May 29, 2011 at 2:19 PM, Jed Brown <jed at 59a2.org> wrote:
>
>> http://petsc.cs.iit.edu/petsc/petsc-dev/rev/f7baf28c7a57
>>
>> The second argument to pow() and variants that might be called through
>> PetscPowScalar() has scalar type. Int should be promoted to scalar. Does it
>> just need "1.0*i" to deal with some C++ case where promotion is not
>> automatic? Casting to a specific sort of int here is really weird.
>>
>
> From the signature and compiler error, that second argument 'p' is
> PetscInt. If PetscInt is 64-bit, there is no overloaded
> method. I did not promote it to Scalar because that seriously slows down
> the code.
>

C++ has overloaded std::pow() to accept an integer power. C does not have a
"pow" with an integer exponent, but many compilers generate special case
code if the argument is known at compile time (not in this case, but can see
it's an int if it checks before promotion).

I guess the question is: what is PetscPowScalar() supposed to be? I have
always thought it was a wrapper for the math.h pow() specified by the C
standard, but polymorphic to operate on arbitrary PetscScalar. If you want a
(scalar)^(integer) function, maybe it should be called PetscPowScalarInt().
I don't think the PowInt typedef is a good general solution.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20110530/e294d152/attachment.html>

Reply via email to