boostorg / qvm

Boost Quaternions, Vectors, Matrices library
Boost Software License 1.0
81 stars 45 forks source link

scalar multiplication "scalar * vector" missing #5

Closed federkamm closed 7 years ago

federkamm commented 7 years ago

It is possible to scale a vector using

vector * scalar

but not using

scalar * vector

Is there a rationale for the missing "scalar * vector" operator? Beside me prefering to write the scalar in front of the vector it is also more efficient in regard of the evaluation order without parantesis

scalar1 * scalar2 * vector == (scalar1 * scalar2) * vector

evaluates in optimal order (n+1 flops where n is the dimension of vector). But

vector * scalar1 * scalar 2 == (vector * scalar1) * scalar2

causes extra evaluations (2n flops) and one is forced to write parantesis for an optimal evaluation order

vector * (scalar1 * scalar2)   [ == scalar1 * scalar2 * vector ]
vector * (scalar1 / scalar2)   [ == scalar1 / scalar2 * vector ]

Please consider adding the "scalar * vector" operator.

zajo commented 7 years ago

Done, see latest develop branch.