Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: compliant solution log2(complex)

...

The header tgmath.h provides type-generic macros for math functions. Although most functions from the math.h header have a complex counterpart in complex.h, several functions do not. Calling any of the following type-generic functions with complex values results in undefined behavior.

...

Code Block
bgColor#ccccff
langc
#include <complex.h>
#include <tgmath.h>
 
void func(void) {
  double complex c = 2.0 + 4.0 * I;
  double complex result = log2(creallog(c)/log(2);
}

Noncompliant Code Example

...