Skip to content

BUG: Zero (complex) to the power of zero (label/scalar) does not follow Gcc/Clang

Summary

There is no agreed value for zero to the power of zero in C++ standard, but C99.

Despite this, Gcc and Clang implementations assume Type(0)^0 = 1.

In OpenFOAM, when Type=complex, the assumption is not followed even though Foam::pow is based on std::pow. When Type=scalar, the above assumption is followed.

Steps to reproduce

Test-A.tar.gz produces the following:

# FOAM: complex(0)^0 #
Foam::pow(Foam::complex, label) = (-nan -nan)
Foam::pow(Foam::complex, scalar) = (-nan -nan)
std::pow(std::complex, label) = (-nan -nan)
std::pow(std::complex, scalar) = (-nan -nan)

# std: complex(0)^0 #
std::complex(scalar,scalar)^scalar = (1,0)

# FOAM: scalar(0)^0 #
Foam::pow(scalar, label) = 1
Foam::pow(scalar, scalar) = 1

# std: scalar(0)^0 #
std::pow(scalar, label) = 1
std::pow(scalar, scalar) = 1

What is the expected correct behavior?

Foam::pow should return whatever std::pow returns for complex types.

Environment information

  • OpenFOAM version : dev
  • Operating system : osuse
  • Compiler : gcc 7
Edited by Kutalmış Berçin