UdonLibrary 1.0.0
機械システム研究部 C++ ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
Float.hpp
[詳解]
1//
2// 固定ビット長浮動小数点型
3//
4// Copyright (c) 2014 Christopher Korman
5// Copyright (c) 2014 John Maddock
6// Copyright (c) 2014 Paul Bristow
7// Copyright (c) 2022-2024 udonrobo
8//
9
10#pragma once
11
12#include <float.h>
13
14#define BOOST_CSTDFLOAT_MAXIMUM_AVAILABLE_WIDTH 0
15#define BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE 0
16#define BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE 0
17#define BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE 0
18#define BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE 0
19
20// Ensure that the compiler has a radix-2 floating-point representation.
21#if (!defined(FLT_RADIX) || ((defined(FLT_RADIX) && (FLT_RADIX != 2))))
22# error The compiler does not support any radix-2 floating-point types required for <boost/cstdfloat.hpp>.
23#endif
24
25// Check if built-in float is equivalent to Float16, Float32, Float64, float80_t, or Float128.
26#if (defined(FLT_MANT_DIG) && defined(FLT_MAX_EXP))
27# if ((FLT_MANT_DIG == 11) && (FLT_MAX_EXP == 16) && (BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE == 0))
28# define BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE float
29# undef BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE
30# define BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE 1
31# elif ((FLT_MANT_DIG == 24) && (FLT_MAX_EXP == 128) && (BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE == 0))
32# define BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE float
33# undef BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE
34# define BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE 1
35# elif ((FLT_MANT_DIG == 53) && (FLT_MAX_EXP == 1024) && (BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE == 0))
36# define BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE float
37# undef BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE
38# define BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE 1
39# elif ((FLT_MANT_DIG == 113) && (FLT_MAX_EXP == 16384) && (BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE == 0))
40# define BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE float
41# undef BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE
42# define BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE 1
43# endif
44#endif
45
46// Check if built-in double is equivalent to Float16, Float32, Float64, float80_t, or Float128.
47#if (defined(DBL_MANT_DIG) && defined(DBL_MAX_EXP))
48# if ((DBL_MANT_DIG == 11) && (DBL_MAX_EXP == 16) && (BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE == 0))
49# define BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE double
50# undef BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE
51# define BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE 1
52# define BOOST_FLOAT16_C(x) (x)
53# elif ((DBL_MANT_DIG == 24) && (DBL_MAX_EXP == 128) && (BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE == 0))
54# define BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE double
55# undef BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE
56# define BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE 1
57# define BOOST_FLOAT32_C(x) (x)
58# elif ((DBL_MANT_DIG == 53) && (DBL_MAX_EXP == 1024) && (BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE == 0))
59# define BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE double
60# undef BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE
61# define BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE 1
62# define BOOST_FLOAT64_C(x) (x)
63# elif ((DBL_MANT_DIG == 113) && (DBL_MAX_EXP == 16384) && (BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE == 0))
64# define BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE double
65# undef BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE
66# define BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE 1
67# endif
68#endif
69
70// Disable check long double capability even if supported by compiler since some math runtime
71// implementations are broken for long double.
72#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
73// Check if built-in long double is equivalent to Float16, Float32, Float64, float80_t, or Float128.
74# if (defined(LDBL_MANT_DIG) && defined(LDBL_MAX_EXP))
75# if ((LDBL_MANT_DIG == 11) && (LDBL_MAX_EXP == 16) && (BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE == 0))
76# define BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE long double
77# undef BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE
78# define BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE 1
79# elif ((LDBL_MANT_DIG == 24) && (LDBL_MAX_EXP == 128) && (BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE == 0))
80# define BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE long double
81# undef BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE
82# define BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE 1
83# elif ((LDBL_MANT_DIG == 53) && (LDBL_MAX_EXP == 1024) && (BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE == 0))
84# define BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE long double
85# undef BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE
86# define BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE 1
87# elif ((LDBL_MANT_DIG == 113) && (LDBL_MAX_EXP == 16384) && (BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE == 0))
88# define BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE long double
89# undef BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE
90# define BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE 1
91# endif
92# endif
93#endif
94
95namespace Udon
96{
97
98 // 定義されている可能性のある型は以下の通りです(処理系によって異なります)
99 // Udon::Float16
100 // Udon::Float32
101 // Udon::Float64
102 // Udon::Float128
103
104#if BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE
105 using Float16 = BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE;
106 static_assert(sizeof(Float16) == 2, "Sorry, it is a typedef bug. I would appreciate it if you could report the error to Issue");
107# undef BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE
108# define UDON_HAS_FLOAT16
109#endif
110
111#if BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE
112 using Float32 = BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE;
113 static_assert(sizeof(Float32) == 4, "Sorry, it is a typedef bug. I would appreciate it if you could report the error to Issue");
114# undef BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE
115# define UDON_HAS_FLOAT32
116#endif
117
118#if BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE
119 using Float64 = BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE;
120 static_assert(sizeof(Float64) == 8, "Sorry, it is a typedef bug. I would appreciate it if you could report the error to Issue");
121# undef BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE
122# define UDON_HAS_FLOAT64
123#endif
124
125#if BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE
126 using Float128 = BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE;
127 static_assert(sizeof(Float128) == 16, "Sorry, it is a typedef bug. I would appreciate it if you could report the error to Issue");
128# undef BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE
129# define UDON_HAS_FLOAT128
130#endif
131
132} // namespace Udon
133
134#undef BOOST_CSTDFLOAT_MAXIMUM_AVAILABLE_WIDTH
135#undef BOOST_CSTDFLOAT_HAS_FLOAT16_NATIVE_TYPE
136#undef BOOST_CSTDFLOAT_HAS_FLOAT32_NATIVE_TYPE
137#undef BOOST_CSTDFLOAT_HAS_FLOAT64_NATIVE_TYPE
138#undef BOOST_CSTDFLOAT_HAS_FLOAT128_NATIVE_TYPE
139
140#undef BOOST_CSTDFLOAT_FLOAT16_NATIVE_TYPE
141#undef BOOST_CSTDFLOAT_FLOAT32_NATIVE_TYPE
142#undef BOOST_CSTDFLOAT_FLOAT64_NATIVE_TYPE
143#undef BOOST_CSTDFLOAT_FLOAT128_NATIVE_TYPE
144
145#undef BOOST_CSTDFLOAT_HAS_FLOAT16
146#undef BOOST_CSTDFLOAT_HAS_FLOAT32
Definition Bit.hpp:12