diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp
index c4cf618c..4fbd4c9a 100644
--- a/include/nlohmann/detail/output/binary_writer.hpp
+++ b/include/nlohmann/detail/output/binary_writer.hpp
@@ -195,7 +195,7 @@ class binary_writer
                 else
                 {
                     if (static_cast<double>(j.m_value.number_float) >= static_cast<double>(std::numeric_limits<float>::lowest()) and
-                            static_cast<double>(j.m_value.number_float) <= static_cast<double>(std::numeric_limits<float>::max()) and
+                            static_cast<double>(j.m_value.number_float) <= static_cast<double>((std::numeric_limits<float>::max)()) and
                             static_cast<double>(static_cast<float>(j.m_value.number_float)) == static_cast<double>(j.m_value.number_float))
                     {
                         oa->write_character(get_cbor_float_prefix(static_cast<float>(j.m_value.number_float)));
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index ed622b9a..5202845d 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -12206,7 +12206,7 @@ class binary_writer
                 else
                 {
                     if (static_cast<double>(j.m_value.number_float) >= static_cast<double>(std::numeric_limits<float>::lowest()) and
-                            static_cast<double>(j.m_value.number_float) <= static_cast<double>(std::numeric_limits<float>::max()) and
+                            static_cast<double>(j.m_value.number_float) <= static_cast<double>((std::numeric_limits<float>::max)()) and
                             static_cast<double>(static_cast<float>(j.m_value.number_float)) == static_cast<double>(j.m_value.number_float))
                     {
                         oa->write_character(get_cbor_float_prefix(static_cast<float>(j.m_value.number_float)));
diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp
index 2a53bb52..873940f9 100644
--- a/test/src/unit-cbor.cpp
+++ b/test/src/unit-cbor.cpp
@@ -925,7 +925,7 @@ TEST_CASE("CBOR")
                 }
                 SECTION("3.40282e+38(max float)")
                 {
-                    float v = std::numeric_limits<float>::max();
+                    float v = (std::numeric_limits<float>::max)();
                     json j = v;
                     std::vector<uint8_t> expected =
                     {
@@ -953,7 +953,7 @@ TEST_CASE("CBOR")
                 }
                 SECTION("1 + 3.40282e+38(more than max float)")
                 {
-                    double v = static_cast<double>(std::numeric_limits<float>::max()) + 0.1e+34;
+                    double v = static_cast<double>((std::numeric_limits<float>::max)()) + 0.1e+34;
                     json j = v;
                     std::vector<uint8_t> expected =
                     {