QuantitativeBytes / qbLinAlg

QuantitativeBytes Linear Algebra Library [C++]. A simple implementation of various common linear algebra functions, intended for educational purposes.
MIT License
44 stars 12 forks source link

qbVector.h Normalize could have issue with the division of two ints. #4

Open rondor1 opened 2 years ago

rondor1 commented 2 years ago

Function Normalize could have the issue of two integer division. Specifically, line: 158 in file https://github.com/QuantitativeBytes/qbLinAlg/blob/main/qbVector.h.

` template qbVector qbVector::Normalized() { // Compute the vector norm. T vecNorm = this->norm();

// Compute the normalized version of the vector.
qbVector<T> result(m_vectorData);
return result * (static_cast<T>(1.0) / vecNorm);

} `

In case type T is substituted to int, the decimal part of 1.0 will be left out. vecNorm is T type as well, and in case this is int, the overall result will be 0.

Would you like me to create a branch, which will solve this issue?