Skip to content

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

@rondor1

Description

@rondor1

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions