[libc-commits] [libc] [libc][complex] implement different flavors of `creal` and `cimag` functions (PR #113300)

Shourya Goel via libc-commits libc-commits at lists.llvm.org
Thu Oct 31 04:31:54 PDT 2024


================
@@ -0,0 +1,21 @@
+//===-- Implementation of cimag function ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/complex/cimag.h"
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(double, cimag, (_Complex double x)) {
+  double *xCmplxPtr = reinterpret_cast<double *>(&x);
----------------
Sh0g0-1758 wrote:

Sure. Just one thing, the struct will probably be : 

```
template <typename T>
struct Complex {
  T real;
  T imag;
};
```

to make it trivially constructable and trivially copyable. 

https://github.com/llvm/llvm-project/pull/113300


More information about the libc-commits mailing list