Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfloat16.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2016 by Southwest Research Institute (R)
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QFLOAT16_H
6#define QFLOAT16_H
7
8#include <QtCore/qcompare.h>
9#include <QtCore/qglobal.h>
10#include <QtCore/qhashfunctions.h>
11#include <QtCore/qmath.h>
12#include <QtCore/qnamespace.h>
13#include <QtCore/qtconfigmacros.h>
14#include <QtCore/qtformat_impl.h>
15#include <QtCore/qtypes.h>
16
17#include <limits>
18#include <string.h>
19#include <type_traits>
20
21#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__AVX2__) && !defined(__F16C__)
22// All processors that support AVX2 do support F16C too, so we could enable the
23// feature unconditionally if __AVX2__ is defined. However, all currently
24// supported compilers except Microsoft's are able to define __F16C__ on their
25// own when the user enables the feature, so we'll trust them.
26# if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
27# define __F16C__ 1
28# endif
29#endif
30
31#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
32#include <immintrin.h>
33#endif
34
35QT_BEGIN_NAMESPACE
36
37#if 0
38#pragma qt_class(QFloat16)
39#pragma qt_no_master_include
40#endif
41
42#ifndef QT_NO_DATASTREAM
43class QDataStream;
44#endif
45class QTextStream;
46
48{
49 struct Wrap
50 {
51 // To let our private constructor work, without other code seeing
52 // ambiguity when constructing from int, double &c.
53 quint16 b16;
54 constexpr inline explicit Wrap(int value) : b16(quint16(value)) {}
55 };
56
57 template <typename T>
59
60public:
62
63 static constexpr bool IsNative = QFLOAT16_IS_NATIVE;
65
66 constexpr inline qfloat16() noexcept : b16(0) {}
67 explicit qfloat16(Qt::Initialization) noexcept { }
68
69#if QFLOAT16_IS_NATIVE
70 constexpr inline qfloat16(NativeType f) : nf(f) {}
71 constexpr operator NativeType() const noexcept { return nf; }
72#else
73 inline qfloat16(float f) noexcept;
74 inline operator float() const noexcept;
75#endif
76 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, NearestFloat>>>
77 constexpr explicit qfloat16(T value) noexcept : qfloat16(NearestFloat(value)) {}
78
79 // Support for qIs{Inf,NaN,Finite}:
80 bool isInf() const noexcept { return (b16 & 0x7fff) == 0x7c00; }
81 bool isNaN() const noexcept { return (b16 & 0x7fff) > 0x7c00; }
82 bool isFinite() const noexcept { return (b16 & 0x7fff) < 0x7c00; }
83 Q_CORE_EXPORT int fpClassify() const noexcept;
84 // Can't specialize std::copysign() for qfloat16
85 qfloat16 copySign(qfloat16 sign) const noexcept
86 { return qfloat16(Wrap((sign.b16 & 0x8000) | (b16 & 0x7fff))); }
87 // Support for std::numeric_limits<qfloat16>
88
89#ifdef __STDCPP_FLOAT16_T__
90private:
92public:
93 static constexpr qfloat16 _limit_epsilon() noexcept { return Bounds::epsilon(); }
94 static constexpr qfloat16 _limit_min() noexcept { return Bounds::min(); }
95 static constexpr qfloat16 _limit_denorm_min() noexcept { return Bounds::denorm_min(); }
96 static constexpr qfloat16 _limit_max() noexcept { return Bounds::max(); }
97 static constexpr qfloat16 _limit_lowest() noexcept { return Bounds::lowest(); }
98 static constexpr qfloat16 _limit_infinity() noexcept { return Bounds::infinity(); }
99 static constexpr qfloat16 _limit_quiet_NaN() noexcept { return Bounds::quiet_NaN(); }
100#if QT_CONFIG(signaling_nan)
101 static constexpr qfloat16 _limit_signaling_NaN() noexcept { return Bounds::signaling_NaN(); }
102#endif
103#else
104 static constexpr qfloat16 _limit_epsilon() noexcept { return qfloat16(Wrap(0x1400)); }
105 static constexpr qfloat16 _limit_min() noexcept { return qfloat16(Wrap(0x400)); }
106 static constexpr qfloat16 _limit_denorm_min() noexcept { return qfloat16(Wrap(1)); }
107 static constexpr qfloat16 _limit_max() noexcept { return qfloat16(Wrap(0x7bff)); }
108 static constexpr qfloat16 _limit_lowest() noexcept { return qfloat16(Wrap(0xfbff)); }
109 static constexpr qfloat16 _limit_infinity() noexcept { return qfloat16(Wrap(0x7c00)); }
110 static constexpr qfloat16 _limit_quiet_NaN() noexcept { return qfloat16(Wrap(0x7e00)); }
111#if QT_CONFIG(signaling_nan)
112 static constexpr qfloat16 _limit_signaling_NaN() noexcept { return qfloat16(Wrap(0x7d00)); }
113#endif
114#endif
115 inline constexpr bool isNormal() const noexcept
116 { return (b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00; }
117private:
118 // ABI note: Qt 6's qfloat16 began with just a quint16 member so it ended
119 // up passed in general purpose registers in any function call taking
120 // qfloat16 by value (it has trivial copy constructors). This means the
121 // integer member in the anonymous union below must remain until a
122 // binary-incompatible version of Qt. If you remove it, on platforms using
123 // the System V ABI for C, the native type is passed in FP registers.
124 union {
126#if QFLOAT16_IS_NATIVE
127 NativeType nf;
128#endif
129 };
130 constexpr inline explicit qfloat16(Wrap nibble) noexcept :
131#if QFLOAT16_IS_NATIVE && defined(__cpp_lib_bit_cast)
132 nf(std::bit_cast<NativeType>(nibble.b16))
133#else
134 b16(nibble.b16)
135#endif
136 {}
137
138 Q_CORE_EXPORT static const quint32 mantissatable[];
139 Q_CORE_EXPORT static const quint32 exponenttable[];
140 Q_CORE_EXPORT static const quint32 offsettable[];
141 Q_CORE_EXPORT static const quint16 basetable[];
142 Q_CORE_EXPORT static const quint16 shifttable[];
143 Q_CORE_EXPORT static const quint32 roundtable[];
144
145 friend bool qIsNull(qfloat16 f) noexcept;
146
147 friend inline qfloat16 operator-(qfloat16 a) noexcept
148 {
149 qfloat16 f;
150 f.b16 = a.b16 ^ quint16(0x8000);
151 return f;
152 }
153
154 friend inline qfloat16 operator+(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<NearestFloat>(a) + static_cast<NearestFloat>(b)); }
155 friend inline qfloat16 operator-(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<NearestFloat>(a) - static_cast<NearestFloat>(b)); }
156 friend inline qfloat16 operator*(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<NearestFloat>(a) * static_cast<NearestFloat>(b)); }
157 friend inline qfloat16 operator/(qfloat16 a, qfloat16 b) noexcept { return qfloat16(static_cast<NearestFloat>(a) / static_cast<NearestFloat>(b)); }
158
159 friend size_t qHash(qfloat16 key, size_t seed = 0) noexcept
160 { return qHash(float(key), seed); } // 6.4 algorithm, so keep using it; ### Qt 7: fix QTBUG-116077
161
162QT_WARNING_PUSH
163QT_WARNING_DISABLE_GCC("-Wfloat-conversion")
164
165#define QF16_MAKE_ARITH_OP_FP(FP, OP)
166 friend inline FP operator OP(qfloat16 lhs, FP rhs) noexcept { return static_cast<FP>(lhs) OP rhs; }
167 friend inline FP operator OP(FP lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<FP>(rhs); }
168#define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP)
169 friend inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept
170 { lhs = qfloat16(NearestFloat(static_cast<FP>(lhs) OP rhs)); return lhs; }
171#define QF16_MAKE_ARITH_OP(FP)
172 QF16_MAKE_ARITH_OP_FP(FP, +)
173 QF16_MAKE_ARITH_OP_FP(FP, -)
174 QF16_MAKE_ARITH_OP_FP(FP, *)
175 QF16_MAKE_ARITH_OP_FP(FP, /)
176 QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +)
177 QF16_MAKE_ARITH_OP_EQ_FP(FP, -=, -)
178 QF16_MAKE_ARITH_OP_EQ_FP(FP, *=, *)
179 QF16_MAKE_ARITH_OP_EQ_FP(FP, /=, /)
180
181 QF16_MAKE_ARITH_OP(long double)
182 QF16_MAKE_ARITH_OP(double)
183 QF16_MAKE_ARITH_OP(float)
184#if QFLOAT16_IS_NATIVE
186#endif
187#undef QF16_MAKE_ARITH_OP
188#undef QF16_MAKE_ARITH_OP_FP
189
190#define QF16_MAKE_ARITH_OP_INT(OP)
191 friend inline double operator OP(qfloat16 lhs, int rhs) noexcept { return static_cast<double>(lhs) OP rhs; }
192 friend inline double operator OP(int lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<double>(rhs); }
193
198#undef QF16_MAKE_ARITH_OP_INT
199
201
202#if QFLOAT16_IS_NATIVE
203# define QF16_CONSTEXPR constexpr
204# define QF16_PARTIALLY_ORDERED Q_DECLARE_PARTIALLY_ORDERED_LITERAL_TYPE
205#else
206# define QF16_CONSTEXPR
207# define QF16_PARTIALLY_ORDERED Q_DECLARE_PARTIALLY_ORDERED
208#endif
209
210 friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, const qfloat16 &rhs) noexcept
211 { return static_cast<NearestFloat>(lhs) == static_cast<NearestFloat>(rhs); }
212 friend QF16_CONSTEXPR
214 { return Qt::compareThreeWay(static_cast<NearestFloat>(lhs), static_cast<NearestFloat>(rhs)); }
216
217#define QF16_MAKE_ORDER_OP_FP(FP)
218 friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, FP rhs) noexcept
219 { return static_cast<FP>(lhs) == rhs; }
220 friend QF16_CONSTEXPR
221 Qt::partial_ordering compareThreeWay(const qfloat16 &lhs, FP rhs) noexcept
222 { return Qt::compareThreeWay(static_cast<FP>(lhs), rhs); }
223 QF16_PARTIALLY_ORDERED(qfloat16, FP)
224
225 QF16_MAKE_ORDER_OP_FP(long double)
228#if QFLOAT16_IS_NATIVE
230#endif
231#undef QF16_MAKE_ORDER_OP_FP
232
233 template <typename T, if_type_is_integral<T> = true>
234 friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, T rhs) noexcept
235 { return static_cast<NearestFloat>(lhs) == static_cast<NearestFloat>(rhs); }
236 template <typename T, if_type_is_integral<T> = true>
238 { return Qt::compareThreeWay(static_cast<NearestFloat>(lhs), static_cast<NearestFloat>(rhs)); }
239
247 QF16_PARTIALLY_ORDERED(qfloat16, unsigned long)
250#ifdef QT_SUPPORTS_INT128
253#endif
254
255#undef QF16_PARTIALLY_ORDERED
256#undef QF16_CONSTEXPR
257
259
260#ifndef QT_NO_DATASTREAM
263#endif
266};
267
269
270Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) noexcept;
271Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) noexcept;
272
273// Complement qnumeric.h:
274[[nodiscard]] inline bool qIsInf(qfloat16 f) noexcept { return f.isInf(); }
275[[nodiscard]] inline bool qIsNaN(qfloat16 f) noexcept { return f.isNaN(); }
276[[nodiscard]] inline bool qIsFinite(qfloat16 f) noexcept { return f.isFinite(); }
277[[nodiscard]] inline int qFpClassify(qfloat16 f) noexcept { return f.fpClassify(); }
278// [[nodiscard]] quint32 qFloatDistance(qfloat16 a, qfloat16 b);
279
280[[nodiscard]] inline qfloat16 qSqrt(qfloat16 f)
281{
282#if defined(__cpp_lib_extended_float) && defined(__STDCPP_FLOAT16_T__) && 0
283 // https://wg21.link/p1467 - disabled until tested
284 using namespace std;
285 return sqrt(f);
286#elif QFLOAT16_IS_NATIVE && defined(__HAVE_FLOAT16) && __HAVE_FLOAT16
287 // This C library (glibc) has sqrtf16().
288 return sqrtf16(f);
289#else
290 bool mathUpdatesErrno = true;
291# if defined(__NO_MATH_ERRNO__) || defined(_M_FP_FAST)
292 mathUpdatesErrno = false;
293# elif defined(math_errhandling)
294 mathUpdatesErrno = (math_errhandling & MATH_ERRNO);
295# endif
296
297 // We don't need to set errno to EDOM if (f >= 0 && f != -0 && !isnan(f))
298 // (or if we don't care about errno in the first place). We can merge the
299 // NaN check with by negating and inverting: !(0 > f), and leaving zero to
300 // sqrtf().
301 if (!mathUpdatesErrno || !(0 > f)) {
302# if defined(__AVX512FP16__)
303 __m128h v = _mm_set_sh(f);
304 v = _mm_sqrt_sh(v, v);
305 return _mm_cvtsh_h(v);
306# endif
307 }
308
309 // WG14's N2601 does not provide a way to tell which types an
310 // implementation supports, so we assume it doesn't and fall back to FP32
311 float f32 = float(f);
312 f32 = sqrtf(f32);
313 return qfloat16::NearestFloat(f32);
314#endif
315}
316
317// The remainder of these utility functions complement qglobal.h
318[[nodiscard]] inline int qRound(qfloat16 d) noexcept
319{ return qRound(static_cast<float>(d)); }
320
321[[nodiscard]] inline qint64 qRound64(qfloat16 d) noexcept
322{ return qRound64(static_cast<float>(d)); }
323
324[[nodiscard]] inline bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
325{
326 qfloat16::NearestFloat f1 = static_cast<qfloat16::NearestFloat>(p1);
327 qfloat16::NearestFloat f2 = static_cast<qfloat16::NearestFloat>(p2);
328 // The significand precision for IEEE754 half precision is
329 // 11 bits (10 explicitly stored), or approximately 3 decimal
330 // digits. In selecting the fuzzy comparison factor of 102.5f
331 // (that is, (2^10+1)/10) below, we effectively select a
332 // window of about 1 (least significant) decimal digit about
333 // which the two operands can vary and still return true.
334 return (qAbs(f1 - f2) * 102.5f <= qMin(qAbs(f1), qAbs(f2)));
335}
336
337/*!
338 \internal
339*/
340[[nodiscard]] inline bool qFuzzyIsNull(qfloat16 f) noexcept
341{
342 return qAbs(f) < 0.00976f; // 1/102.5 to 3 significant digits; see qFuzzyCompare()
343}
344
345[[nodiscard]] inline bool qIsNull(qfloat16 f) noexcept
346{
347 return (f.b16 & static_cast<quint16>(0x7fff)) == 0;
348}
349
350inline int qIntCast(qfloat16 f) noexcept
351{ return int(static_cast<qfloat16::NearestFloat>(f)); }
352
353#if !defined(Q_QDOC) && !QFLOAT16_IS_NATIVE
355QT_WARNING_DISABLE_CLANG("-Wc99-extensions")
356QT_WARNING_DISABLE_GCC("-Wold-style-cast")
357inline qfloat16::qfloat16(float f) noexcept
358{
359#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
360 __m128 packsingle = _mm_set_ss(f);
361 __m128i packhalf = _mm_cvtps_ph(packsingle, 0);
362 b16 = _mm_extract_epi16(packhalf, 0);
363#elif defined (__ARM_FP16_FORMAT_IEEE)
364 __fp16 f16 = __fp16(f);
365 memcpy(&b16, &f16, sizeof(quint16));
366#else
367 quint32 u;
368 memcpy(&u, &f, sizeof(quint32));
369 const quint32 signAndExp = u >> 23;
370 const quint16 base = basetable[signAndExp];
371 const quint16 shift = shifttable[signAndExp];
372 const quint32 round = roundtable[signAndExp];
373 quint32 mantissa = (u & 0x007fffff);
374 if ((signAndExp & 0xff) == 0xff) {
375 if (mantissa) // keep nan from truncating to inf
376 mantissa = qMax(1U << shift, mantissa);
377 } else {
378 // Round half to even. First round up by adding one in the most
379 // significant bit we'll be discarding:
380 mantissa += round;
381 // If the last bit we'll be keeping is now set, but all later bits are
382 // clear, we were at half and shouldn't have rounded up; decrement will
383 // clear this last kept bit. Any later set bit hides the decrement.
384 if (mantissa & (1 << shift))
385 --mantissa;
386 }
387
388 // We use add as the mantissa may overflow causing
389 // the exp part to shift exactly one value.
390 b16 = quint16(base + (mantissa >> shift));
391#endif
392}
393QT_WARNING_POP
394
395inline qfloat16::operator float() const noexcept
396{
397#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
398 __m128i packhalf = _mm_cvtsi32_si128(b16);
399 __m128 packsingle = _mm_cvtph_ps(packhalf);
400 return _mm_cvtss_f32(packsingle);
401#elif defined (__ARM_FP16_FORMAT_IEEE)
402 __fp16 f16;
403 memcpy(&f16, &b16, sizeof(quint16));
404 return float(f16);
405#else
406 quint32 u = mantissatable[offsettable[b16 >> 10] + (b16 & 0x3ff)]
407 + exponenttable[b16 >> 10];
408 float f;
409 memcpy(&f, &u, sizeof(quint32));
410 return f;
411#endif
412}
413#endif // Q_QDOC and non-native
414
415/*
416 qHypot compatibility; see ../kernel/qmath.h
417*/
418namespace QtPrivate {
419template <> struct QHypotType<qfloat16, qfloat16>
420{
421 using type = qfloat16;
422};
423template <typename R> struct QHypotType<R, qfloat16>
424{
426};
427template <typename R> struct QHypotType<qfloat16, R> : QHypotType<R, qfloat16>
428{
429};
430}
431
432// Avoid passing qfloat16 to std::hypot(), while ensuring return types
433// consistent with the above:
434inline auto qHypot(qfloat16 x, qfloat16 y)
435{
436#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__) || QFLOAT16_IS_NATIVE
437 return QtPrivate::QHypotHelper<qfloat16>(x).add(y).result();
438#else
439 return qfloat16(qHypot(float(x), float(y)));
440#endif
441}
442
443// in ../kernel/qmath.h
444template<typename F, typename ...Fs> auto qHypot(F first, Fs... rest);
445
446template <typename T> typename QtPrivate::QHypotType<T, qfloat16>::type
447qHypot(T x, qfloat16 y)
448{
449 if constexpr (std::is_floating_point_v<T>)
450 return qHypot(x, float(y));
451 else
452 return qHypot(qfloat16(x), y);
453}
454template <typename T> auto qHypot(qfloat16 x, T y)
455{
456 return qHypot(y, x);
457}
458
459#if defined(__cpp_lib_hypot) && __cpp_lib_hypot >= 201603L // Expected to be true
460// If any are not qfloat16, convert each qfloat16 to float:
461/* (The following splits the some-but-not-all-qfloat16 cases up, using
462 (X|Y|Z)&~(X&Y&Z) = X ? ~(Y&Z) : Y|Z = X&~(Y&Z) | ~X&Y | ~X&~Y&Z,
463 into non-overlapping cases, to avoid ambiguity.) */
464template <typename Ty, typename Tz,
465 typename std::enable_if<
466 // Ty, Tz aren't both qfloat16:
467 !(std::is_same_v<qfloat16, Ty> && std::is_same_v<qfloat16, Tz>), int>::type = 0>
468auto qHypot(qfloat16 x, Ty y, Tz z) { return qHypot(qfloat16::NearestFloat(x), y, z); }
469template <typename Tx, typename Tz,
470 typename std::enable_if<
471 // Tx isn't qfloat16:
472 !std::is_same_v<qfloat16, Tx>, int>::type = 0>
473auto qHypot(Tx x, qfloat16 y, Tz z) { return qHypot(x, qfloat16::NearestFloat(y), z); }
474template <typename Tx, typename Ty,
475 typename std::enable_if<
476 // Neither Tx nor Ty is qfloat16:
477 !std::is_same_v<qfloat16, Tx> && !std::is_same_v<qfloat16, Ty>, int>::type = 0>
478auto qHypot(Tx x, Ty y, qfloat16 z) { return qHypot(x, y, qfloat16::NearestFloat(z)); }
479
480// If all are qfloat16, stay with qfloat16 (albeit via float, if no native support):
481inline auto qHypot(qfloat16 x, qfloat16 y, qfloat16 z)
482{
483#if (defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)) || QFLOAT16_IS_NATIVE
484 return QtPrivate::QHypotHelper<qfloat16>(x).add(y).add(z).result();
485#else
486 return qfloat16(qHypot(float(x), float(y), float(z)));
487#endif
488}
489#endif // 3-arg std::hypot() is available
490
491QT_END_NAMESPACE
492
493namespace std {
494template<>
496{
497public:
498 /*
499 Treat quint16 b16 as if it were:
500 uint S: 1; // b16 >> 15 (sign); can be set for zero
501 uint E: 5; // (b16 >> 10) & 0x1f (offset exponent)
502 uint M: 10; // b16 & 0x3ff (adjusted mantissa)
503
504 for E == 0: magnitude is M / 2.^{24}
505 for 0 < E < 31: magnitude is (1. + M / 2.^{10}) * 2.^{E - 15)
506 for E == 31: not finite
507 */
508 static constexpr int digits = 11;
509 static constexpr int min_exponent = -13;
510 static constexpr int max_exponent = 16;
511
512 static constexpr int digits10 = 3;
513 static constexpr int max_digits10 = 5;
514 static constexpr int min_exponent10 = -4;
515 static constexpr int max_exponent10 = 4;
516
519 static constexpr QT_PREPEND_NAMESPACE(qfloat16) (min)()
523 static constexpr QT_PREPEND_NAMESPACE(qfloat16) (max)()
531#if QT_CONFIG(signaling_nan)
534#else
535 static constexpr bool has_signaling_NaN = false;
536#endif
537};
538
543template<> class numeric_limits<const volatile QT_PREPEND_NAMESPACE(qfloat16)>
545
546// Adding overloads to std isn't allowed, so we can't extend this to support
547// for fpclassify(), isnormal() &c. (which, furthermore, are macros on MinGW).
548} // namespace std
549
550// std::format support
551#ifdef QT_SUPPORTS_STD_FORMAT
552
553QT_BEGIN_NAMESPACE
554
555namespace QtPrivate {
556
557// [format.formatter.spec] / 5
558template <typename T, typename CharT>
559constexpr bool FormatterDoesNotExist =
560 std::negation_v<
561 std::disjunction<
562 std::is_default_constructible<std::formatter<T, CharT>>,
563 std::is_copy_constructible<std::formatter<T, CharT>>,
564 std::is_move_constructible<std::formatter<T, CharT>>,
565 std::is_copy_assignable<std::formatter<T, CharT>>,
566 std::is_move_assignable<std::formatter<T, CharT>>
567 >
568 >;
569
570template <typename CharT>
571using QFloat16FormatterBaseType =
572 std::conditional_t<FormatterDoesNotExist<qfloat16::NearestFloat, CharT>,
573 float,
574 qfloat16::NearestFloat>;
575
576} // namespace QtPrivate
577
578QT_END_NAMESPACE
579
580namespace std {
581template <typename CharT>
582struct formatter<QT_PREPEND_NAMESPACE(qfloat16), CharT>
583 : std::formatter<QT_PREPEND_NAMESPACE(QtPrivate::QFloat16FormatterBaseType<CharT>), CharT>
584{
585 template <typename FormatContext>
586 auto format(QT_PREPEND_NAMESPACE(qfloat16) val, FormatContext &ctx) const
587 {
588 using FloatType = QT_PREPEND_NAMESPACE(QtPrivate::QFloat16FormatterBaseType<CharT>);
589 return std::formatter<FloatType, CharT>::format(FloatType(val), ctx);
590 }
591};
592} // namespace std
593
594#endif // QT_SUPPORTS_STD_FORMAT
595
596#endif // QFLOAT16_H
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
Definition qfloat16.h:48
constexpr qfloat16() noexcept
Definition qfloat16.h:66
quint16 b16
Definition qfloat16.h:125
constexpr bool isNormal() const noexcept
Definition qfloat16.h:115
static constexpr qfloat16 _limit_quiet_NaN() noexcept
Definition qfloat16.h:110
static constexpr qfloat16 _limit_min() noexcept
Definition qfloat16.h:105
bool isInf() const noexcept
Definition qfloat16.h:80
static constexpr qfloat16 _limit_infinity() noexcept
Definition qfloat16.h:109
static constexpr qfloat16 _limit_epsilon() noexcept
Definition qfloat16.h:104
static constexpr bool IsNative
Definition qfloat16.h:63
static constexpr qfloat16 _limit_denorm_min() noexcept
Definition qfloat16.h:106
bool isNaN() const noexcept
Definition qfloat16.h:81
friend qfloat16 operator/(qfloat16 a, qfloat16 b) noexcept
Definition qfloat16.h:157
friend qfloat16 operator-(qfloat16 a, qfloat16 b) noexcept
Definition qfloat16.h:155
friend size_t qHash(qfloat16 key, size_t seed=0) noexcept
Definition qfloat16.h:159
Q_CORE_EXPORT int fpClassify() const noexcept
Definition qfloat16.cpp:145
friend bool qIsNull(qfloat16 f) noexcept
Definition qfloat16.h:345
bool isFinite() const noexcept
Definition qfloat16.h:82
static constexpr qfloat16 _limit_lowest() noexcept
Definition qfloat16.h:108
friend qfloat16 operator+(qfloat16 a, qfloat16 b) noexcept
Definition qfloat16.h:154
friend qfloat16 operator*(qfloat16 a, qfloat16 b) noexcept
Definition qfloat16.h:156
friend qfloat16 operator-(qfloat16 a) noexcept
Definition qfloat16.h:147
operator float() const noexcept
Definition qfloat16.h:395
qfloat16 copySign(qfloat16 sign) const noexcept
Definition qfloat16.h:85
static constexpr qfloat16 _limit_max() noexcept
Definition qfloat16.h:107
constexpr qfloat16(T value) noexcept
Definition qfloat16.h:77
QTextStream & operator>>(QTextStream &ts, qfloat16 &f16)
Definition qfloat16.cpp:425
static bool hasFastF16()
Definition qfloat16.cpp:326
static void qFloatToFloat16_fast(quint16 *, const float *, qsizetype) noexcept
Definition qfloat16.cpp:331
static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) noexcept
Definition qfloat16.cpp:336
QDataStream & operator>>(QDataStream &ds, qfloat16 &f)
Definition qfloat16.cpp:419
#define QF16_MAKE_ARITH_OP_INT(OP)
Definition qfloat16.h:190
bool qIsFinite(qfloat16 f) noexcept
Definition qfloat16.h:276
#define QF16_MAKE_ARITH_OP(FP)
Definition qfloat16.h:171
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:324
Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) noexcept
auto qHypot(qfloat16 x, T y)
Definition qfloat16.h:454
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:340
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:275
int qFpClassify(qfloat16 f) noexcept
Definition qfloat16.h:277
bool qIsInf(qfloat16 f) noexcept
Definition qfloat16.h:274
Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE)
auto qHypot(qfloat16 x, qfloat16 y)
Definition qfloat16.h:434
#define QF16_MAKE_ORDER_OP_FP(FP)
Definition qfloat16.h:217
#define QF16_CONSTEXPR
Definition qfloat16.h:206
#define QF16_PARTIALLY_ORDERED
Definition qfloat16.h:207
Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) noexcept
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:280
qint64 qRound64(qfloat16 d) noexcept
Definition qfloat16.h:321
#define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP)
Definition qfloat16.h:168
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:318
int qIntCast(qfloat16 f) noexcept
Definition qfloat16.h:350
auto qHypot(F first, Fs... rest)
Definition qmath.h:136