/src/WasmEdge/include/common/nan.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/common/nan.h - NaN helpers -------------------------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains helpers for the NaN rules of the WebAssembly spec. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "experimental/math.hpp" |
17 | | |
18 | | #include <cstdint> |
19 | | #include <limits> |
20 | | #include <type_traits> |
21 | | |
22 | | namespace WasmEdge { |
23 | | |
24 | | /// Unsigned integer with the same size as the floating-point type T. |
25 | | template <typename T> |
26 | | using FloatBits = std::conditional_t<sizeof(T) == 4, uint32_t, uint64_t>; |
27 | | |
28 | | /// The most significant payload bit of T, which is set in a quiet NaN. |
29 | | template <typename T> |
30 | | inline constexpr FloatBits<T> QuietBit = |
31 | | FloatBits<T>{1} << (std::numeric_limits<T>::digits - 2); |
32 | | |
33 | | /// Value with the most significant payload bit set when it is a NaN, which |
34 | | /// makes it an arithmetic NaN. Non-NaN values are returned unchanged. |
35 | 0 | template <typename T> inline T quietNaN(T Value) noexcept { |
36 | 0 | return cxx26::quiet_nan(Value); |
37 | 0 | } Unexecuted instantiation: float WasmEdge::quietNaN<float>(float) Unexecuted instantiation: double WasmEdge::quietNaN<double>(double) |
38 | | |
39 | | } // namespace WasmEdge |