Repository: nlohmann/json
File: include/nlohmann/detail/output/binary_writer.hpp (C++)

Code before:
                    oa->write_character(to_char_type(0x18));
                    write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
                }
                else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
                {
                    oa->write_character(to_char_type(0x19));
                    write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
                }
                else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
                {
                    oa->write_character(to_char_type(0x1A));
                    write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
                }
                else
                {
                    oa->write_character(to_char_type(0x1B));
                    write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
                }
                break;
            }

            case value_t::number_float:
            {
		const auto valueD = j.m_value.number_float;
		const float valueF = static_cast<float>(valueD);
		if (std::isnan(valueD)) {
		    // NaN is 0xf97e00 in CBOR
		    oa->write_character(to_char_type(0xF9));
		    oa->write_character(to_char_type(0x7E));
		    oa->write_character(to_char_type(0x00));
		} else if (std::isinf(valueD)) {
		    // Infinity is 0xf97c00, -Infinity is 0xf9fc00
		    oa->write_character(to_char_type(0xf9));
		    oa->write_character(valueD > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
		    oa->write_character(to_char_type(0x00));
		} else {
                    if(static_cast<double>(valueF) == valueD) {
		        oa->write_character(get_cbor_float_prefix(valueF));
		        write_number(valueF);
                    } else {
		        oa->write_character(get_cbor_float_prefix(valueD));
		        write_number(valueD);
                    }
		}
                break;
            }

            case value_t::string:
            {
                // step 1: write control byte and the string length
                const auto N = j.m_value.string->size();

Review comment (suggestion):
Please include `<cmath>` to include/nlohmann/detail/output/binary_writer.hpp to use `std::isnan` and `std::isinf`.

Code after:
                {
                    oa->write_character(to_char_type(0x18));
                    write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
                }
                else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
                {
                    oa->write_character(to_char_type(0x19));
                    write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
                }
                else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
                {
                    oa->write_character(to_char_type(0x1A));
                    write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
                }
                else
                {
                    oa->write_character(to_char_type(0x1B));
                    write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
                }
                break;
            }

            case value_t::number_float:
            {
                if (std::isnan(j.m_value.number_float))
                {
                    // NaN is 0xf97e00 in CBOR
                    oa->write_character(to_char_type(0xF9));
                    oa->write_character(to_char_type(0x7E));
                    oa->write_character(to_char_type(0x00));
                }
                else if (std::isinf(j.m_value.number_float))
                {
                    // Infinity is 0xf97c00, -Infinity is 0xf9fc00
                    oa->write_character(to_char_type(0xf9));
                    oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
                    oa->write_character(to_char_type(0x00));
                }
                else
                {
                    if (j.m_value.number_float >= std::numeric_limits<float>::lowest() and
                            j.m_value.number_float <= std::numeric_limits<float>::max() and
                            static_cast<double>(static_cast<float>(j.m_value.number_float)) == j.m_value.number_float)
                    {
                        oa->write_character(get_cbor_float_prefix(static_cast<float>(j.m_value.number_float)));
                        write_number(static_cast<float>(j.m_value.number_float));
                    }
                    else
                    {
                        oa->write_character(get_cbor_float_prefix(j.m_value.number_float));
                        write_number(j.m_value.number_float);