From cdf84c330a395a31120190f990a724c50a901eef Mon Sep 17 00:00:00 2001
From: Yen-Chen Chen <yen-chen.chen@kit.edu>
Date: Thu, 4 Apr 2024 11:23:18 +0000
Subject: [PATCH] Fix real64 accuracy downscaled falsely
 (icon-libraries/libfortran-support!82)

## What is the bug
The accuracy of the expression evaluation code was falsely downscaled in the code.
## How do you fix it
The false test did not pop up because of a bug in FortUTF. See https://gitlab.dkrz.de/icon-libraries/libfortran-support/-/issues/18

Merged-by: Jonas Jucker <jonas.jucker@env.ethz.ch>
Changelog: bugfix
---
 src/mo_expression.F90            | 2 +-
 test/fortran/test_expression.f90 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mo_expression.F90 b/src/mo_expression.F90
index 17d9be3..4bcdf73 100644
--- a/src/mo_expression.F90
+++ b/src/mo_expression.F90
@@ -442,7 +442,7 @@ CONTAINS
       SELECT CASE (cqueue%list(i)%etype)
       CASE (VALUE)
         ALLOCATE (op_value)
-        op_value%val = REAL(cqueue%list(i)%val)
+        op_value%val = REAL(cqueue%list(i)%val, KIND=real_kind)
         expr_list%list(i)%p => op_value
       CASE (VARIABLE)
         ALLOCATE (op_variable)
diff --git a/test/fortran/test_expression.f90 b/test/fortran/test_expression.f90
index cda64a8..4920693 100644
--- a/test/fortran/test_expression.f90
+++ b/test/fortran/test_expression.f90
@@ -50,7 +50,7 @@ CONTAINS
 
     CALL TAG_TEST("TEST_exp_erf")
     formula = expression("exp(1.) + erf(0.76)")
-    ref = EXP(1.) + ERF(0.76)
+    ref = EXP(1._wp) + ERF(0.76_wp)
     CALL formula%evaluate(ptr_val)
     CALL ASSERT_ALMOST_EQUAL(val, ref)
 
-- 
GitLab