From f1dad14807ae9650c66d83ec35fbc016b91ac471 Mon Sep 17 00:00:00 2001
From: Alex Henrie <alexhenrie24@gmail.com>
Date: Wed, 12 Jul 2017 18:05:09 +0200
Subject: [PATCH] msvcr120: Add acosh.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 configure                                     |  2 +
 configure.ac                                  |  2 +
 .../api-ms-win-crt-math-l1-1-0.spec           |  6 +--
 dlls/msvcr120/msvcr120.spec                   |  6 +--
 dlls/msvcr120_app/msvcr120_app.spec           |  6 +--
 dlls/msvcrt/math.c                            | 45 +++++++++++++++++++
 dlls/ucrtbase/ucrtbase.spec                   |  6 +--
 include/config.h.in                           |  6 +++
 8 files changed, 67 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index f6053f19b55..199d4d8b11d 100755
--- a/configure
+++ b/configure
@@ -17406,6 +17406,8 @@ $as_echo "#define HAVE_ISNAN 1" >>confdefs.h
 fi
 
 for ac_func in \
+	acosh \
+	acoshf \
 	asinh \
 	asinhf \
 	cbrt \
diff --git a/configure.ac b/configure.ac
index d557df82dac..3974dd5818e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2594,6 +2594,8 @@ then
 fi
 
 AC_CHECK_FUNCS(\
+	acosh \
+	acoshf \
 	asinh \
 	asinhf \
 	cbrt \
diff --git a/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec b/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec
index 5d2499b782f..5c644326ced 100644
--- a/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec
+++ b/dlls/api-ms-win-crt-math-l1-1-0/api-ms-win-crt-math-l1-1-0.spec
@@ -124,9 +124,9 @@
 @ cdecl _yn(long double) ucrtbase._yn
 @ cdecl acos(double) ucrtbase.acos
 @ cdecl -arch=arm,x86_64 acosf(float) ucrtbase.acosf
-@ stub acosh
-@ stub acoshf
-@ stub acoshl
+@ cdecl acosh(double) ucrtbase.acosh
+@ cdecl acoshf(float) ucrtbase.acoshf
+@ cdecl acoshl(double) ucrtbase.acoshl
 @ cdecl asin(double) ucrtbase.asin
 @ cdecl -arch=arm,x86_64 asinf(float) ucrtbase.asinf
 @ cdecl asinh(double) ucrtbase.asinh
diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec
index 989a3cb572d..7899622f69c 100644
--- a/dlls/msvcr120/msvcr120.spec
+++ b/dlls/msvcr120/msvcr120.spec
@@ -2011,9 +2011,9 @@
 @ cdecl abs(long) MSVCRT_abs
 @ cdecl acos(double) MSVCRT_acos
 @ cdecl -arch=arm,x86_64 acosf(float) MSVCRT_acosf
-@ stub acosh
-@ stub acoshf
-@ stub acoshl
+@ cdecl acosh(double) MSVCR120_acosh
+@ cdecl acoshf(float) MSVCR120_acoshf
+@ cdecl acoshl(double) MSVCR120_acoshl
 @ cdecl asctime(ptr) MSVCRT_asctime
 @ cdecl asctime_s(ptr long ptr) MSVCRT_asctime_s
 @ cdecl asin(double) MSVCRT_asin
diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec
index 345bb51a106..9a5da20ca8b 100644
--- a/dlls/msvcr120_app/msvcr120_app.spec
+++ b/dlls/msvcr120_app/msvcr120_app.spec
@@ -1677,9 +1677,9 @@
 @ cdecl abs(long) msvcr120.abs
 @ cdecl acos(double) msvcr120.acos
 @ cdecl -arch=arm,x86_64 acosf(float) msvcr120.acosf
-@ stub acosh
-@ stub acoshf
-@ stub acoshl
+@ cdecl acosh(double) msvcr120.acosh
+@ cdecl acoshf(float) msvcr120.acoshf
+@ cdecl acoshl(double) msvcr120.acoshl
 @ cdecl asctime(ptr) msvcr120.asctime
 @ cdecl asctime_s(ptr long ptr) msvcr120.asctime_s
 @ cdecl asin(double) msvcr120.asin
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 387aab3b524..17edf47dfaa 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -2898,6 +2898,51 @@ LDOUBLE CDECL MSVCR120_asinhl(LDOUBLE x)
     return MSVCR120_asinh(x);
 }
 
+/*********************************************************************
+ *      acosh (MSVCR120.@)
+ */
+double CDECL MSVCR120_acosh(double x)
+{
+    if (x < 1) *MSVCRT__errno() = MSVCRT_EDOM;
+
+#ifdef HAVE_ACOSH
+    return acosh(x);
+#else
+    if (x < 1) {
+        MSVCRT_fenv_t env;
+
+        MSVCRT_fegetenv(&env);
+        env.status |= MSVCRT__SW_INVALID;
+        MSVCRT_fesetenv(&env);
+        return NAN;
+    }
+    if (!isfinite(x*x)) return log(2) + log(x);
+    return log(x + sqrt(x*x-1));
+#endif
+}
+
+/*********************************************************************
+ *      acoshf (MSVCR120.@)
+ */
+float CDECL MSVCR120_acoshf(float x)
+{
+#ifdef HAVE_ACOSHF
+    if (x < 1) *MSVCRT__errno() = MSVCRT_EDOM;
+
+    return acoshf(x);
+#else
+    return MSVCR120_acosh(x);
+#endif
+}
+
+/*********************************************************************
+ *      acoshl (MSVCR120.@)
+ */
+LDOUBLE CDECL MSVCR120_acoshl(LDOUBLE x)
+{
+    return MSVCR120_acosh(x);
+}
+
 /*********************************************************************
  *      _scalb  (MSVCRT.@)
  *      scalbn  (MSVCR120.@)
diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec
index 3e7c79564cc..1eae07222d7 100644
--- a/dlls/ucrtbase/ucrtbase.spec
+++ b/dlls/ucrtbase/ucrtbase.spec
@@ -2153,9 +2153,9 @@
 @ cdecl abs(long) MSVCRT_abs
 @ cdecl acos(double) MSVCRT_acos
 @ cdecl -arch=arm,x86_64 acosf(float) MSVCRT_acosf
-@ stub acosh
-@ stub acoshf
-@ stub acoshl
+@ cdecl acosh(double) MSVCR120_acosh
+@ cdecl acoshf(float) MSVCR120_acoshf
+@ cdecl acoshl(double) MSVCR120_acoshl
 @ cdecl asctime(ptr) MSVCRT_asctime
 @ cdecl asctime_s(ptr long ptr) MSVCRT_asctime_s
 @ cdecl asin(double) MSVCRT_asin
diff --git a/include/config.h.in b/include/config.h.in
index c28755911a0..4a9acca5471 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -10,6 +10,12 @@
 /* Define to the file extension for executables. */
 #undef EXEEXT
 
+/* Define to 1 if you have the `acosh' function. */
+#undef HAVE_ACOSH
+
+/* Define to 1 if you have the `acoshf' function. */
+#undef HAVE_ACOSHF
+
 /* Define to 1 if you have the <alias.h> header file. */
 #undef HAVE_ALIAS_H
 
-- 
GitLab