splinterz
9th July 2014, 01:28
i have a function that returns a double value (eg. 1.76896558753375)
then i append the value to a QVector<double> with some_vector.append(value)
after append, the value is 1.76897 in the qvector.
why is this happening and how can it be prevented?
stepping through qvector's append function:
template <typename T>
void QVector<T>::append(const T &t)
{
const T copy(t);
const bool isTooSmall = uint(d->size + 1) > d->alloc;
if (!isDetached() || isTooSmall) {
QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default);
reallocData(d->size, isTooSmall ? d->size + 1 : d->alloc, opt);
}
if (QTypeInfo<T>::isComplex)
new (d->end()) T(copy);
else
*d->end() = copy;
++d->size;
}
both t and copy are the correct un-rounded value until ++d->size, after that line, the rounded value is appended instead of the full value.
then i append the value to a QVector<double> with some_vector.append(value)
after append, the value is 1.76897 in the qvector.
why is this happening and how can it be prevented?
stepping through qvector's append function:
template <typename T>
void QVector<T>::append(const T &t)
{
const T copy(t);
const bool isTooSmall = uint(d->size + 1) > d->alloc;
if (!isDetached() || isTooSmall) {
QArrayData::AllocationOptions opt(isTooSmall ? QArrayData::Grow : QArrayData::Default);
reallocData(d->size, isTooSmall ? d->size + 1 : d->alloc, opt);
}
if (QTypeInfo<T>::isComplex)
new (d->end()) T(copy);
else
*d->end() = copy;
++d->size;
}
both t and copy are the correct un-rounded value until ++d->size, after that line, the rounded value is appended instead of the full value.