forked from msgpack/msgpack-c
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat signaling NaN correctly.
- Loading branch information
Showing
10 changed files
with
415 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// MessagePack for C++ NaN utility | ||
// | ||
// Copyright (C) 2023 KONDO Takatoshi | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
#ifndef MSGPACK_NAN_UTIL_HPP | ||
#define MSGPACK_NAN_UTIL_HPP | ||
|
||
#include "msgpack/v1/nan_util.hpp" | ||
#include "msgpack/v2/nan_util.hpp" | ||
#include "msgpack/v3/nan_util.hpp" | ||
|
||
#endif // MSGPACK_NAN_UTIL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// MessagePack for C++ NaN utility | ||
// | ||
// Copyright (C) 2023 KONDO Takatoshi | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
#ifndef MSGPACK_V1_NAN_UTIL_HPP | ||
#define MSGPACK_V1_NAN_UTIL_HPP | ||
|
||
#include <limits> | ||
#include <cfloat> | ||
#include <cmath> | ||
#include <cstdint> | ||
|
||
#include <msgpack/assert.hpp> | ||
|
||
namespace msgpack { | ||
|
||
/// @cond | ||
MSGPACK_API_VERSION_NAMESPACE(v1) { | ||
/// @endcond | ||
|
||
inline bool is_quiet_nan(double const& nan_val) { | ||
MSGPACK_ASSERT(nan_val != nan_val); | ||
uint64_t bit_pattern = reinterpret_cast<uint64_t const&>(nan_val); | ||
int is_quiet_bit_index = DBL_MANT_DIG - 2; | ||
return (bit_pattern >> is_quiet_bit_index) & 1; | ||
} | ||
|
||
inline bool is_quiet_nan(float const& nan_val) { | ||
MSGPACK_ASSERT(nan_val != nan_val); | ||
uint32_t bit_pattern = reinterpret_cast<uint32_t const&>(nan_val); | ||
int is_quiet_bit_index = FLT_MANT_DIG - 2; | ||
return (bit_pattern >> is_quiet_bit_index) & 1; | ||
} | ||
|
||
inline void clear_quiet(double& nan_val) { | ||
MSGPACK_ASSERT(nan_val != nan_val); | ||
int is_quiet_bit_index = DBL_MANT_DIG - 2; | ||
uint64_t mask = uint64_t(1) << is_quiet_bit_index; | ||
reinterpret_cast<uint64_t&>(nan_val) &= ~mask; | ||
} | ||
|
||
inline void clear_quiet(float& nan_val) { | ||
MSGPACK_ASSERT(nan_val != nan_val); | ||
int is_quiet_bit_index = FLT_MANT_DIG - 2; | ||
uint64_t mask = uint64_t(1) << is_quiet_bit_index; | ||
reinterpret_cast<uint32_t&>(nan_val) &= ~mask; | ||
} | ||
|
||
/// @cond | ||
} // MSGPACK_API_VERSION_NAMESPACE(v1) | ||
/// @endcond | ||
|
||
} // namespace msgpack | ||
|
||
#endif // MSGPACK_V1_NAN_UTIL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// MessagePack for C++ NaN utility | ||
// | ||
// Copyright (C) 2023 KONDO Takatoshi | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
#ifndef MSGPACK_V2_NAN_UTIL_HPP | ||
#define MSGPACK_V2_NAN_UTIL_HPP | ||
|
||
#include "msgpack/v1/nan_util.hpp" | ||
|
||
|
||
namespace msgpack { | ||
|
||
/// @cond | ||
MSGPACK_API_VERSION_NAMESPACE(v2) { | ||
/// @endcond | ||
|
||
using v1::is_quiet_nan; | ||
using v1::clear_quiet; | ||
|
||
/// @cond | ||
} // MSGPACK_API_VERSION_NAMESPACE(v2) | ||
/// @endcond | ||
|
||
} // namespace msgpack | ||
|
||
#endif // MSGPACK_V2_NAN_UTIL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// MessagePack for C++ NaN utility | ||
// | ||
// Copyright (C) 2023 KONDO Takatoshi | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
#ifndef MSGPACK_V3_NAN_UTIL_HPP | ||
#define MSGPACK_V3_NAN_UTIL_HPP | ||
|
||
#include "msgpack/v2/nan_util.hpp" | ||
|
||
|
||
namespace msgpack { | ||
|
||
/// @cond | ||
MSGPACK_API_VERSION_NAMESPACE(v3) { | ||
/// @endcond | ||
|
||
using v2::is_quiet_nan; | ||
using v2::clear_quiet; | ||
|
||
/// @cond | ||
} // MSGPACK_API_VERSION_NAMESPACE(v3) | ||
/// @endcond | ||
|
||
} // namespace msgpack | ||
|
||
#endif // MSGPACK_V3_NAN_UTIL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.