From b263d752d8af83569517aa56ef17facfa26adc91 Mon Sep 17 00:00:00 2001
From: zy69guqi <richard.angersbach@fau.de>
Date: Wed, 15 Jan 2025 16:39:39 +0100
Subject: [PATCH] Add functions for numeric limits (to be supported by the
 backends)

---
 src/pystencils/backend/functions.py             | 10 ++++++++++
 src/pystencils/backend/platforms/generic_cpu.py |  4 +++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/pystencils/backend/functions.py b/src/pystencils/backend/functions.py
index 388160f30..ea0d6cb9d 100644
--- a/src/pystencils/backend/functions.py
+++ b/src/pystencils/backend/functions.py
@@ -94,6 +94,16 @@ class MathFunctions(Enum):
         self.num_args = num_args
 
 
+class NumericLimitsFunctions(MathFunctions):
+    """Numerical limits functions supported by the backend.
+
+    Each platform has to materialize these functions to a concrete implementation.
+    """
+
+    min = ("min", 0)
+    max = ("max", 0)
+
+
 class PsMathFunction(PsFunction):
     """Homogenously typed mathematical functions."""
 
diff --git a/src/pystencils/backend/platforms/generic_cpu.py b/src/pystencils/backend/platforms/generic_cpu.py
index b6d7dd551..affeb34d4 100644
--- a/src/pystencils/backend/platforms/generic_cpu.py
+++ b/src/pystencils/backend/platforms/generic_cpu.py
@@ -43,7 +43,7 @@ class GenericCpu(Platform):
 
     @property
     def required_headers(self) -> set[str]:
-        return {"<math.h>"}
+        return {"<math.h>", "<climits.h"}
 
     def materialize_iteration_space(
         self, body: PsBlock, ispace: IterationSpace
@@ -62,6 +62,8 @@ class GenericCpu(Platform):
         dtype = call.get_dtype()
         arg_types = (dtype,) * func.num_args
 
+        # TODO: numeric limits
+
         if isinstance(dtype, PsIeeeFloatType) and dtype.width in (32, 64):
             cfunc: CFunction
             match func:
-- 
GitLab