History

Handling NaN values for floats

Atlante45 committed 12 years ago

Commit 5a8569f1 parent 75573a44 files · +343 −28Browse files

Showing the changes to libraries/script-engine/src/DataViewPrototype.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/DataViewPrototype.cpp+13−9
@@ -32,10 +32,7 @@ bool DataViewPrototype::realOffset(qint32& offset, size_t size) const { · 31 unmodified lines
3232 }
3333 quint32 viewOffset = thisObject().data().property(BYTE_OFFSET_PROPERTY_NAME).toInt32();
3434 quint32 viewLength = thisObject().data().property(BYTE_LENGTH_PROPERTY_NAME).toInt32();
35− //qDebug() << "View Offset: " << viewOffset << ", View Lenght: " << viewLength;
36− //qDebug() << "Offset: " << offset << ", Size: " << size;
3735 offset += viewOffset;
38− //qDebug() << "New offset: " << offset << ", bool: " << ((offset + size) <= viewOffset + viewLength);
3936 return (offset + size) <= viewOffset + viewLength;
4037 }
4138
@@ -123,7 +120,7 @@ quint32 DataViewPrototype::getUint32(qint32 byteOffset, bool littleEndian) { · 81 unmodified lines
123120 return 0;
124121 }
125122
126−float DataViewPrototype::getFloat32(qint32 byteOffset, bool littleEndian) {
123+QScriptValue DataViewPrototype::getFloat32(qint32 byteOffset, bool littleEndian) {
127124 if (realOffset(byteOffset, sizeof(float))) {
128125 QDataStream stream(*thisArrayBuffer());
129126 stream.skipRawData(byteOffset);
@@ -132,14 +129,17 @@ float DataViewPrototype::getFloat32(qint32 byteOffset, bool littleEndian) { · 2 unmodified lines
132129
133130 float result;
134131 stream >> result;
135− qDebug() << "Get: " << result;
136− return result;
132+ if (isNaN(result)) {
133+ return QScriptValue(NAN);
134+ }
135+
136+ return QScriptValue(result);
137137 }
138138 thisObject().engine()->evaluate("throw \"RangeError: byteOffset out of range\"");
139− return 0;
139+ return QScriptValue();
140140 }
141141
142−double DataViewPrototype::getFloat64(qint32 byteOffset, bool littleEndian) {
142+QScriptValue DataViewPrototype::getFloat64(qint32 byteOffset, bool littleEndian) {
143143 if (realOffset(byteOffset, sizeof(double))) {
144144 QDataStream stream(*thisArrayBuffer());
145145 stream.skipRawData(byteOffset);
@@ -148,10 +148,14 @@ double DataViewPrototype::getFloat64(qint32 byteOffset, bool littleEndian) { · 2 unmodified lines
148148
149149 double result;
150150 stream >> result;
151+ if (isNaN(result)) {
152+ return QScriptValue();
153+ }
154+
151155 return result;
152156 }
153157 thisObject().engine()->evaluate("throw \"RangeError: byteOffset out of range\"");
154− return 0;
158+ return QScriptValue();
155159 }
156160
157161 ///////////////// SETTERS ////////////////////////////