Constantinos Glynos
Constantinos Glynos

Reputation: 3186

Multiply glm::vec3 with boost multiprecision float

Boost offers a multiprecision library for floating-point values which is awesome, but glm does not allow for it to be multiplied with a vector or matrix or pretty much anything as it does not know what it is.

So the code below does not compile:

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <glm/glm.hpp>

int main()
{
    typedef boost::multiprecision::cpp_dec_float_50 mp_float;

    float a = 0.1f;
    mp_float b = 0.1f;

    glm::vec3 foo(1.f,1.f,1.f);

    glm::vec3 v1 = a * foo; // OK
    glm::vec3 v2 = b * foo; // COMPILER ERROR
}

Is there a way to make this work without having to go and write class wrappers and operator overloading member functions? ( I would really really like to avoid this )

Or if anyone knows another method of multiplying with glm and high precision numbers, I would appreciate it.

Thank you

Upvotes: 1

Views: 2296

Answers (2)

Constantinos Glynos
Constantinos Glynos

Reputation: 3186

Seems like multiprecision is not accepted by other libs..

Templates will save a lot of code, but at the end, one would have to specialize for the different operations! Also, it is possible to end up in the same problem when multiplying mp_float with T, and if T is float, then back to stage 0!

The best thing so far is to avoid using boost multiprecision with the glm library and control the precision with numeric_limits and rounding up numbers to 6 decimal places.

That's what I've ended up using and it works like a charm!

Upvotes: 0

Emily
Emily

Reputation: 541

You can overload operators without wrapper classes:

glm::vec3 operator *(mp_float f, glm::vec3 v) {
    // ...
}

Note, though, that glm::vec3 only holds normal floats, so you'll lose some precision doing this no matter how you do it.

Upvotes: 1

Related Questions