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/qtypes.h>
20#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__AVX2__) && !defined(__F16C__)
25# if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
30#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
37#pragma qt_class(QFloat16)
38#pragma qt_no_master_include
41#ifndef QT_NO_DATASTREAM
56#ifdef QT_SUPPORTS_INT128
58 using IsIntegral = std::disjunction<std::is_integral<T>,
59 std::is_same<std::remove_const_t<T>, qint128>,
60 std::is_same<std::remove_const_t<T>,
quint128>>;
63 using IsIntegral = std::is_integral<T>;
66 using if_type_is_integral = std::enable_if_t<IsIntegral<std::remove_reference_t<T>>
::value,
72 static constexpr bool IsNative = QFLOAT16_IS_NATIVE;
73 using NearestFloat = std::conditional_t<IsNative, NativeType, float>;
80 constexpr operator NativeType() const noexcept {
return nf; }
83 inline operator float() const noexcept;
85 template <
typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, NearestFloat>>>
89 bool isInf() const noexcept {
return (
b16 & 0x7fff) == 0x7c00; }
90 bool isNaN() const noexcept {
return (
b16 & 0x7fff) > 0x7c00; }
91 bool isFinite() const noexcept {
return (
b16 & 0x7fff) < 0x7c00; }
98#ifdef __STDCPP_FLOAT16_T__
100 using Bounds = std::numeric_limits<NativeType>;
109#if QT_CONFIG(signaling_nan)
110 static constexpr qfloat16 _limit_signaling_NaN() noexcept {
return Bounds::signaling_NaN(); }
120#if QT_CONFIG(signaling_nan)
121 static constexpr qfloat16 _limit_signaling_NaN() noexcept {
return qfloat16(Wrap(0x7d00)); }
125 {
return (
b16 & 0x7c00) && (
b16 & 0x7c00) != 0x7c00; }
135#if QFLOAT16_IS_NATIVE
139 constexpr inline explicit qfloat16(Wrap nibble) noexcept :
140#if QFLOAT16_IS_NATIVE && defined(__cpp_lib_bit_cast)
141 nf(std::bit_cast<NativeType>(nibble.b16))
147 Q_CORE_EXPORT
static const quint32 mantissatable[];
148 Q_CORE_EXPORT
static const quint32 exponenttable[];
149 Q_CORE_EXPORT
static const quint32 offsettable[];
150 Q_CORE_EXPORT
static const quint16 basetable[];
151 Q_CORE_EXPORT
static const quint16 shifttable[];
152 Q_CORE_EXPORT
static const quint32 roundtable[];
174#define QF16_MAKE_ARITH_OP_FP(FP, OP) \
175 friend inline FP operator OP(qfloat16 lhs, FP rhs) noexcept { return static_cast<FP>(lhs) OP rhs; } \
176 friend inline FP operator OP(FP lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<FP>(rhs); }
177#define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP) \
178 friend inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) noexcept \
179 { lhs = qfloat16(NearestFloat(static_cast<FP>(lhs) OP rhs)); return lhs; }
180#define QF16_MAKE_ARITH_OP(FP) \
181 QF16_MAKE_ARITH_OP_FP(FP, +) \
182 QF16_MAKE_ARITH_OP_FP(FP, -) \
183 QF16_MAKE_ARITH_OP_FP(FP, *) \
184 QF16_MAKE_ARITH_OP_FP(FP, /) \
185 QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
186 QF16_MAKE_ARITH_OP_EQ_FP(FP, -=, -) \
187 QF16_MAKE_ARITH_OP_EQ_FP(FP, *=, *) \
188 QF16_MAKE_ARITH_OP_EQ_FP(FP, /=, /)
193#if QFLOAT16_IS_NATIVE
196#undef QF16_MAKE_ARITH_OP
197#undef QF16_MAKE_ARITH_OP_FP
199#define QF16_MAKE_ARITH_OP_INT(OP) \
200 friend inline double operator OP(qfloat16 lhs, int rhs) noexcept { return static_cast<double>(lhs) OP rhs; } \
201 friend inline double operator OP(int lhs, qfloat16 rhs) noexcept { return lhs OP static_cast<double>(rhs); }
207#undef QF16_MAKE_ARITH_OP_INT
211#if QFLOAT16_IS_NATIVE
212# define QF16_CONSTEXPR constexpr
213# define QF16_PARTIALLY_ORDERED Q_DECLARE_PARTIALLY_ORDERED_LITERAL_TYPE
215# define QF16_CONSTEXPR
216# define QF16_PARTIALLY_ORDERED Q_DECLARE_PARTIALLY_ORDERED
226#define QF16_MAKE_ORDER_OP_FP(FP) \
227 friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, FP rhs) noexcept \
228 { return static_cast<FP>(lhs) == rhs; } \
229 friend QF16_CONSTEXPR \
230 Qt::partial_ordering compareThreeWay(const qfloat16 &lhs, FP rhs) noexcept \
231 { return Qt::compareThreeWay(static_cast<FP>(lhs), rhs); } \
232 QF16_PARTIALLY_ORDERED(qfloat16, FP)
237#if QFLOAT16_IS_NATIVE
240#undef QF16_MAKE_ORDER_OP_FP
242 template <
typename T, if_type_is_
integral<T> = true>
245 template <
typename T, if_type_is_
integral<T> = true>
259#ifdef QT_SUPPORTS_INT128
264#undef QF16_PARTIALLY_ORDERED
269#ifndef QT_NO_DATASTREAM
291#if defined(__cpp_lib_extended_float) && defined(__STDCPP_FLOAT16_T__) && 0
295#elif QFLOAT16_IS_NATIVE && defined(__HAVE_FLOAT16) && __HAVE_FLOAT16
299 bool mathUpdatesErrno =
true;
300# if defined(__NO_MATH_ERRNO__) || defined(_M_FP_FAST)
301 mathUpdatesErrno =
false;
302# elif defined(math_errhandling)
303 mathUpdatesErrno = (math_errhandling & MATH_ERRNO);
310 if (!mathUpdatesErrno || !(0 >
f)) {
311# if defined(__AVX512FP16__)
312 __m128h
v = _mm_set_sh(
f);
313 v = _mm_sqrt_sh(
v,
v);
314 return _mm_cvtsh_h(
v);
320 float f32 = float(
f);
328{
return qRound(
static_cast<float>(
d)); }
331{
return qRound64(
static_cast<float>(
d)); }
351 return qAbs(
f) < 0.00976f;
356 return (
f.b16 &
static_cast<quint16>(0x7fff)) == 0;
362#if !defined(Q_QDOC) && !QFLOAT16_IS_NATIVE
368#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
369 __m128 packsingle = _mm_set_ss(
f);
370 __m128i packhalf = _mm_cvtps_ph(packsingle, 0);
371 b16 = _mm_extract_epi16(packhalf, 0);
372#elif defined (__ARM_FP16_FORMAT_IEEE)
373 __fp16 f16 = __fp16(
f);
374 memcpy(&b16, &f16,
sizeof(
quint16));
378 const quint32 signAndExp = u >> 23;
381 const quint32 round = roundtable[signAndExp];
382 quint32 mantissa = (u & 0x007fffff);
383 if ((signAndExp & 0xff) == 0xff) {
393 if (mantissa & (1 <<
shift))
404inline qfloat16::operator float() const noexcept
406#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
407 __m128i packhalf = _mm_cvtsi32_si128(b16);
408 __m128 packsingle = _mm_cvtph_ps(packhalf);
409 return _mm_cvtss_f32(packsingle);
410#elif defined (__ARM_FP16_FORMAT_IEEE)
412 memcpy(&f16, &b16,
sizeof(
quint16));
415 quint32 u = mantissatable[offsettable[b16 >> 10] + (b16 & 0x3ff)]
416 + exponenttable[b16 >> 10];
434 using type = std::conditional_t<std::is_floating_point_v<R>,
R,
double>;
445#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__) || QFLOAT16_IS_NATIVE
453template<
typename F,
typename ...Fs>
auto qHypot(F
first, Fs... rest);
458 if constexpr (std::is_floating_point_v<T>)
468#if defined(__cpp_lib_hypot) && __cpp_lib_hypot >= 201603L
473template <
typename Ty,
typename Tz,
474 typename std::enable_if<
476 !(std::is_same_v<qfloat16, Ty> && std::is_same_v<qfloat16, Tz>),
int>
::type = 0>
478template <
typename Tx,
typename Tz,
479 typename std::enable_if<
481 !std::is_same_v<qfloat16, Tx>,
int>
::type = 0>
483template <
typename Tx,
typename Ty,
484 typename std::enable_if<
486 !std::is_same_v<qfloat16, Tx> && !std::is_same_v<qfloat16, Ty>,
int>
::type = 0>
492#if (defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)) || QFLOAT16_IS_NATIVE
504class numeric_limits<QT_PREPEND_NAMESPACE(
qfloat16)> :
public numeric_limits<float>
518 static constexpr int min_exponent = -13;
519 static constexpr int max_exponent = 16;
521 static constexpr int digits10 = 3;
522 static constexpr int max_digits10 = 5;
523 static constexpr int min_exponent10 = -4;
524 static constexpr int max_exponent10 = 4;
527 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_epsilon(); }
529 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_min(); }
531 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_denorm_min(); }
533 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_max(); }
535 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_lowest(); }
537 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_infinity(); }
539 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_quiet_NaN(); }
540#if QT_CONFIG(signaling_nan)
541 static constexpr QT_PREPEND_NAMESPACE(
qfloat16) signaling_NaN()
542 {
return QT_PREPEND_NAMESPACE(
qfloat16)::_limit_signaling_NaN(); }
544 static constexpr bool has_signaling_NaN =
false;
548template<>
class numeric_limits<const QT_PREPEND_NAMESPACE(
qfloat16)>
549 :
public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};
550template<>
class numeric_limits<volatile QT_PREPEND_NAMESPACE(
qfloat16)>
551 :
public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};
552template<>
class numeric_limits<const volatile QT_PREPEND_NAMESPACE(
qfloat16)>
553 :
public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};
\inmodule QtCore\reentrant
auto add(F first, Fs... rest) const
\variable Qt::weak_ordering::less
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
friend QF16_CONSTEXPR Qt::partial_ordering compareThreeWay(const qfloat16 &lhs, T rhs) noexcept
friend size_t qHash(qfloat16 key, size_t seed=0) noexcept
friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, const qfloat16 &rhs) noexcept
constexpr qfloat16() noexcept
constexpr bool isNormal() const noexcept
static constexpr qfloat16 _limit_quiet_NaN() noexcept
QtPrivate::NativeFloat16Type NativeType
friend Q_CORE_EXPORT QDataStream & operator>>(QDataStream &ds, qfloat16 &f)
static constexpr qfloat16 _limit_min() noexcept
bool isInf() const noexcept
static constexpr qfloat16 _limit_infinity() noexcept
friend bool qIsNull(qfloat16 f) noexcept
static constexpr qfloat16 _limit_epsilon() noexcept
static constexpr bool IsNative
QT_WARNING_POP friend Q_CORE_EXPORT QDataStream & operator<<(QDataStream &ds, qfloat16 f)
static constexpr qfloat16 _limit_denorm_min() noexcept
bool isNaN() const noexcept
qfloat16(Qt::Initialization) noexcept
friend qfloat16 operator/(qfloat16 a, qfloat16 b) noexcept
friend qfloat16 operator-(qfloat16 a, qfloat16 b) noexcept
std::conditional_t< IsNative, NativeType, float > NearestFloat
Q_CORE_EXPORT int fpClassify() const noexcept
friend QF16_CONSTEXPR bool comparesEqual(const qfloat16 &lhs, T rhs) noexcept
bool isFinite() const noexcept
static constexpr qfloat16 _limit_lowest() noexcept
friend QF16_CONSTEXPR Qt::partial_ordering compareThreeWay(const qfloat16 &lhs, const qfloat16 &rhs) noexcept
friend qfloat16 operator+(qfloat16 a, qfloat16 b) noexcept
friend qfloat16 operator*(qfloat16 a, qfloat16 b) noexcept
friend qfloat16 operator-(qfloat16 a) noexcept
qfloat16 copySign(qfloat16 sign) const noexcept
static constexpr qfloat16 _limit_max() noexcept
constexpr qfloat16(T value) noexcept
static constexpr QT_PREPEND_NAMESPACE qfloat16 max()
static constexpr QT_PREPEND_NAMESPACE(qfloat16) lowest()
static constexpr QT_PREPEND_NAMESPACE(qfloat16) epsilon()
static constexpr QT_PREPEND_NAMESPACE(qfloat16) infinity()
static constexpr QT_PREPEND_NAMESPACE(qfloat16) quiet_NaN()
static constexpr QT_PREPEND_NAMESPACE(qfloat16) denorm_min()
static constexpr QT_PREPEND_NAMESPACE qfloat16 min()
Combined button and popup list for selecting options.
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
static QT_WARNING_DISABLE_FLOAT_COMPARE ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
#define QT_WARNING_DISABLE_FLOAT_COMPARE
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_DISABLE_CLANG(text)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QF16_MAKE_ARITH_OP_INT(OP)
bool qIsFinite(qfloat16 f) noexcept
#define QF16_MAKE_ARITH_OP(FP)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
bool qIsNaN(qfloat16 f) noexcept
int qFpClassify(qfloat16 f) noexcept
bool qIsInf(qfloat16 f) noexcept
auto qHypot(qfloat16 x, qfloat16 y)
bool qIsNull(qfloat16 f) noexcept
#define QF16_MAKE_ORDER_OP_FP(FP)
#define QF16_PARTIALLY_ORDERED
Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) noexcept
qfloat16 qSqrt(qfloat16 f)
qint64 qRound64(qfloat16 d) noexcept
int qRound(qfloat16 d) noexcept
int qIntCast(qfloat16 f) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
static const qreal epsilon
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef signed char qint8
std::conditional_t< std::is_floating_point_v< R >, R, double > type
decltype(std::hypot(R(1), F(1))) type