From 8c611fd5d06e19460b3632efb0ce09e1caeafe51 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Camilla=20L=C3=B6wy?= <elmindreda@elmindreda.org>
Date: Tue, 18 Dec 2018 19:15:29 +0100
Subject: [PATCH] Win32: Fix build on older versions of Visual C++

Older versions did not provide fmin or fmax.  This adds internal
versions of fminf and fmaxf that should not be confused with
standards compliant implementations.
---
 src/init.c     | 24 ++++++++++++++++++++++++
 src/input.c    |  2 +-
 src/internal.h |  2 ++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/init.c b/src/init.c
index 9e670d42..4f424c4a 100644
--- a/src/init.c
+++ b/src/init.c
@@ -119,6 +119,30 @@ char* _glfw_strdup(const char* source)
     return result;
 }
 
+float _glfw_fminf(float a, float b)
+{
+    if (a != a)
+        return b;
+    else if (b != b)
+        return a;
+    else if (a < b)
+        return a;
+    else
+        return b;
+}
+
+float _glfw_fmaxf(float a, float b)
+{
+    if (a != a)
+        return b;
+    else if (b != b)
+        return a;
+    else if (a > b)
+        return a;
+    else
+        return b;
+}
+
 
 //////////////////////////////////////////////////////////////////////////
 //////                         GLFW event API                       //////
diff --git a/src/input.c b/src/input.c
index b0bb3de4..460e9f31 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1242,7 +1242,7 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
         if (e->type == _GLFW_JOYSTICK_AXIS)
         {
             const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
-            state->axes[i] = fminf(fmaxf(value, -1.f), 1.f);
+            state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f);
         }
         else if (e->type == _GLFW_JOYSTICK_HATBIT)
         {
diff --git a/src/internal.h b/src/internal.h
index 7be2b267..30c7551a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -766,4 +766,6 @@ void _glfwTerminateVulkan(void);
 const char* _glfwGetVulkanResultString(VkResult result);
 
 char* _glfw_strdup(const char* source);
+float _glfw_fminf(float a, float b);
+float _glfw_fmaxf(float a, float b);