roystgnr / MetaPhysicL

Metaprogramming and operator-overloaded classes for numerical simulations
Other
22 stars 12 forks source link

FPE from `std::pow(ADReal(-1), 1)` #82

Closed dschwen closed 2 years ago

dschwen commented 2 years ago

ADReal being any DualNumber<Real, *> (Real being double). Power of one should be a no op. Floating point exception is unexpected.

dschwen commented 2 years ago

std::pow(ADReal(-1), 2); fails, too. Actually any whole number fails. Fractions will probably fail, too, but for different reasons...

tophmatthews commented 2 years ago

Fraction should fail right?

dschwen commented 2 years ago

but for different reasons...

maeaning: the right reasons

roystgnr commented 2 years ago

Power of one should be a no op.

You mean an identity, right? Just testing whether the exponent is 1 is already an op.

I'm having some trouble replicating this. Could you try out https://github.com/roystgnr/MetaPhysicL/tree/pow_negative_with_int and see if the new tests work or fail for you? Could you let me know what container you've got configured for the gradients in your ADReal? Those new tests are with NumberArray; maybe there's something that works there but fails with a sparse gradient?

dschwen commented 2 years ago

@roystgnr this fails with DualNumber<Real, Real>, too.

roystgnr commented 2 years ago

CI can't seem to replicate the problem with gcc 9.4, gcc 7.5, or clang 5.0.2. If those new tests in https://github.com/libMesh/MetaPhysicL/pull/22 fail for you then let me know as much as you can about your environment? If they pass for you then see if you can add one that fails?

roystgnr commented 2 years ago

This was closed by libMesh/MetaPhysicL#22