[Chapel Merge] Improve how tuples are converted into complex values

Branch: refs/heads/main
Revision: c59a16e813ee2c35a990c8675ad603984584676e
Author: bradcray
Link: Improve how tuples are converted into complex values by bradcray · Pull Request #24184 · chapel-lang/chapel · GitHub
Log Message:
Improve how tuples are converted into complex values (#24184)

[reviewed by @mppf]

This updates the implementation of the _chpl_complexNNN() routines in
the runtime which are used to convert a Chapel 2-tuple of reals into a
complex. Specifically, my rewrite tries to use the 'CMPLX()' initializer
macros rather than math to initialize the complex values. The motivation
for this is to work around an
issue

in which inf/nan values would creep in due to an apparent
bug. See the
output of the test added in this PR prior to this change to see the old,
odd behavior.

When this macro isn't available (as with when using C++ compilers and
potentially some others? CI failed when I didn't have this option
available), I am currently falling back to an aliasing-based approach to
poke the real and imaginary values into the complex and then returning
it. This generates the correct values as well, though feels a bit
squirrely.

By building the runtime with CHPL_DONT_USE_CMPLX_PTR_ALIASING, you can
go back to the original implementation we've used, which performs math
and gets the "mathematically wrong" answer.

If anyone going forward has suggestions for making these conversion
routines work equally well in C as C++ with fewer options involved, I'm
all ears. This was the best I was able to come up with after some
internet browsing.

Compare: Comparing 9192600de0ee96ba5c9ac96618c5007aaace8e09...31687e9d5b4168b072a10cdc95ed08e76ff07155 · chapel-lang/chapel · GitHub

Diff:
M runtime/include/chpltypes.h
A test/types/complex/bradc/tupleToComplex.chpl
A test/types/complex/bradc/tupleToComplex.good
https://github.com/chapel-lang/chapel/pull/24184.diff