Commit 283bce73 authored by hjk's avatar hjk
Browse files

Debugger: Add a qfloat16 dumper



Change-Id: Ibc43da06c195d916296f09740a1111a2586443b8
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent b3771305
......@@ -2758,3 +2758,25 @@ def qdump__QSqlField(d, value):
qdump__QVariant(d, val)
d.putBetterType(d.currentType.value.replace('QVariant', 'QSqlField'))
d.putPlainChildren(value)
def qdump__qfloat16(d, value):
h = value.split('H')[0]
# Stole^H^H^HHeavily inspired by J.F. Sebastian at
# http://math.stackexchange.com/questions/1128204/how-to-convert-
# from-floating-point-binary-to-decimal-in-half-precision16-bits
sign = h >> 15
exp = (h >> 10) & 0b011111
fraction = h & (2**10 - 1)
if exp == 0:
if fraction == 0:
res = -0.0 if sign else 0.0
else:
res = (-1)**sign * fraction / 2**10 * 2**(-14) # subnormal
elif exp == 0b11111:
res = ('-inf' if sign else 'inf') if fraction == 0 else 'nan'
else:
res = (-1)**sign * (1 + fraction / 2**10) * 2**(exp - 15)
d.putValue(res)
d.putNumChild(1)
d.putPlainChildren(value)
......@@ -5244,6 +5244,18 @@ void tst_Dumpers::dumper_data()
+ Check("s32s", "-2147483648", TypeDef("int", "@qint32"));
QTest::newRow("Float")
<< Data("#include <QFloat16>\n",
"qfloat16 f1 = 45.3f; unused(&f1);\n"
"qfloat16 f2 = 45.1f; unused(&f2);\n")
+ CoreProfile()
+ QtVersion(0x50900)
// Using numpy:
// + Check("f1", "45.281", "@qfloat16")
// + Check("f2", "45.094", "@qfloat16");
+ Check("f1", "45.28125", "@qfloat16")
+ Check("f2", "45.09375", "@qfloat16");
QTest::newRow("Enum")
<< Data("\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment