#8292 closed Bugs (fixed)
[multiprecision] et_on with uBLAS become bad result
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
cpp_dec_float
with et_on
with uBLAS become bad result.
following example is basic vector processing with et_on
:
#include <iostream> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/io.hpp> namespace mp = boost::multiprecision; namespace ublas = boost::numeric::ublas; using float_type = mp::number<mp::cpp_dec_float<50>>; using vec = ublas::vector<float_type>; vec make_vector3(float_type x, float_type y, float_type z) { vec v(3); v[0] = x; v[1] = y; v[2] = z; return v; } vec normalize(vec v) { return v / ublas::norm_2(v); } int main() { vec p = make_vector3(0.0f, 0.0f, 0.0f); // now position vec q = make_vector3(3.0f, 0.0f, 6.0f); // target position vec v = normalize(q - p); std::cout << "vector : " << v << std::endl; float_type speed = 0.1f; float_type accel = 0.1f; for (int i = 0; i < 20; ++i) { p += v * speed; speed += accel; } std::cout << "result pos : " << p << std::endl; }
result:
vector : [3](1,0,1) result pos : [3](1,0,1)
this result is bad. should be:
vector : [3](0.447214,0,0.894427) result pos : [3](9.39149,0,18.783)
following code is using et_off
:
#include <iostream> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/io.hpp> namespace mp = boost::multiprecision; namespace ublas = boost::numeric::ublas; using float_type = mp::number<mp::cpp_dec_float<50>, mp::et_off>; using vec = ublas::vector<float_type>; vec make_vector3(float_type x, float_type y, float_type z) { vec v(3); v[0] = x; v[1] = y; v[2] = z; return v; } vec normalize(vec v) { return v / ublas::norm_2(v); } int main() { vec p = make_vector3(0.0f, 0.0f, 0.0f); // now position vec q = make_vector3(3.0f, 0.0f, 6.0f); // target position vec v = normalize(q - p); std::cout << "vector : " << v << std::endl; float_type speed = 0.1f; float_type accel = 0.1f; for (int i = 0; i < 20; ++i) { p += v * speed; speed += accel; } std::cout << "result pos : " << p << std::endl; }
result:
vector : [3](0.447214,0,0.894427) result pos : [3](9.39149,0,18.783)
this result is correct.
And, associated issue is here:
http://stackoverflow.com/questions/14948102/boost-matrix-product-for-multiprecision-numbers
this is et_on
's issue too.
Change History (4)
comment:1 by , 10 years ago
Component: | None → multiprecision |
---|---|
Owner: | set to |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The compiler errors you reported on stack overflow are to be expected - uBlas knows nothing about expression template number types internally and can't currently be used with them.
I'll investigate the runtime issues shortly.