RAM: this function branches a lot. Search for a branchless sqrt?
| 506 | |
| 507 | // RAM: this function branches a lot. Search for a branchless sqrt? |
| 508 | static inline void |
| 509 | _inline_sqrt( npy_complex64 x, npy_complex64 &r ) |
| 510 | { |
| 511 | npy_float32 s, d; |
| 512 | |
| 513 | if (x.real == 0. && x.imag == 0.) |
| 514 | r = x; |
| 515 | else { |
| 516 | s = sqrtf((fabsf(x.real) + hypotf(x.real,x.imag))/2); |
| 517 | d = x.imag/(2*s); |
| 518 | if (x.real > 0.) { |
| 519 | r.real = s; |
| 520 | r.imag = d; |
| 521 | } |
| 522 | else if (x.imag >= 0.) { |
| 523 | r.real = d; |
| 524 | r.imag = s; |
| 525 | } |
| 526 | else { |
| 527 | r.real = -d; |
| 528 | r.imag = -s; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | static inline void |
| 534 | _inline_sqrt( npy_complex128 x, npy_complex128 &r ) |