Skip to content

Instantly share code, notes, and snippets.

@samdmarshall
Created October 18, 2015 17:46
Show Gist options
  • Save samdmarshall/017db3bbfed38a227f8c to your computer and use it in GitHub Desktop.
Save samdmarshall/017db3bbfed38a227f8c to your computer and use it in GitHub Desktop.
/* check that exp(i * pi) == -1 */
#include <math.h> /* for atan */
#include <stdio.h>
#include <complex.h>
#undef complex // complex.h has a macro define for "_Complex" -> "complex" which will break c++ compilation
int
main(void)
{
double pi = 4 * atan(1.0);
double _Complex z = cexp(I * pi); // this will error, see this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59087 (suggestion to avoid the use of "I" in code)
printf("%f + %f * i\n", creal(z), cimag(z));
}
/*
$ clang++ --version
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
$ clang++ test.cpp -o test_example
test.cpp:11:29: error: use of undeclared identifier 'I'
double _Complex z = cexp(I * pi);
^
1 error generated.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment