Make cnormalize return 0 instead of nan

This commit is contained in:
Andrei Alexeyev 2020-04-13 12:15:56 +03:00
parent f1dfa3cdfe
commit d9d6f66458
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4

View file

@ -100,7 +100,9 @@ cmplx capproach_asymptotic_p(cmplx *val, cmplx target, double rate, double epsil
}
cmplx cnormalize(cmplx c) {
return c / cabs(c);
cmplx r = c / sqrt(creal(c)*creal(c) + cimag(c)*cimag(c));
// NOTE: clang generates a function call for isnan()...
return LIKELY(r == r) ? r : 0;
}
cmplx cclampabs(cmplx c, double maxabs) {