From 64a8a8ccbe74e01836e497a5c49e04b2d2b07c1d Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 26 Jun 2024 17:00:28 -0500
Subject: [PATCH] Fix type info for complex -> real scalar C functions

---
 loopy/target/c/__init__.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py
index 4c5d7720..9adfcbdb 100644
--- a/loopy/target/c/__init__.py
+++ b/loopy/target/c/__init__.py
@@ -528,16 +528,19 @@ class CMathCallable(ScalarCallable):
                     dtype))
 
             if name in ["abs", "real", "imag"]:
-                dtype = real_dtype
+                result_dtype = real_dtype
+            else:
+                result_dtype = dtype
 
-            if dtype.kind == "c" or name in ["real", "imag", "abs"]:
+            if dtype.kind == "c":
                 if name != "conj":
                     name = "c" + name
 
             return (
                     self.copy(name_in_target=name,
-                        arg_id_to_dtype={0: NumpyType(dtype), -1:
-                            NumpyType(dtype)}),
+                        arg_id_to_dtype={
+                            0: NumpyType(dtype),
+                            -1: NumpyType(result_dtype)}),
                     callables_table)
 
         # binary functions
-- 
GitLab