# Bug in phase() and log() of complex

**URL:** <https://chapel.discourse.group/t/bug-in-phase-and-log-of-complex/31132>\
**Category:** Users\
**Created:** [March 4, 2024, 2:09pm UTC](https://chapel.discourse.group/t/bug-in-phase-and-log-of-complex/31132 "2024-03-04T14:09:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [March 4, 2024, 2:09pm UTC](https://chapel.discourse.group/t/bug-in-phase-and-log-of-complex/31132/1 "2024-03-04T14:09:03Z")

</div>

The result of `phase()` or `log()` on a complex argument is broken if that argument has a real component of zero. The former is the new name for `carg()`. It might only be in the LLVM version of the compiler. The phase returns a _NaN_. The imaginary component of the complex logarithm (which is the phase of the original argument) also returns an _NaN_. It should be one of `+/-pi/2`.

I can post a simple fix for the former soon but I am not sure what a simple (but still accurate robust) fix for the latter is.

---

<div class="post-metadata">

**Author:** ![lydia](https://avatars.discourse-cdn.com/v4/letter/l/34f0e0/32.png) [@lydia](https://chapel.discourse.group/u/lydia)\
**Post date:** [March 4, 2024, 3:48pm UTC](https://chapel.discourse.group/t/bug-in-phase-and-log-of-complex/31132/2 "2024-03-04T15:48:46Z")

</div>

Huh, thanks for noticing that, Damian! Considering how strongly we rely  
on C's definitions under the covers, it'd probably be worth reporting to  
LLVM as well.

Thanks,  
Lydia

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [March 4, 2024, 10:27pm UTC](https://chapel.discourse.group/t/bug-in-phase-and-log-of-complex/31132/4 "2024-03-04T22:27:26Z")

</div>

Ignore this posting. It was a bug with the casting operator to complex.  
Brad fixed the bug in 8 weeks ago so the problem goes away with the latest release.

I was inadvertently using 1.33.0 to do my testing. Silly me.
