Subject: [Boost-bugs] [Boost C++ Libraries] #8292: [multiprecision] et_on with uBLAS become bad result
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-03-14 09:21:20
#8292: [multiprecision] et_on with uBLAS become bad result
-------------------------------------------------------+--------------------
Reporter: Akira Takahashi <faithandbrave@â¦> | Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.53.0
Severity: Problem | Keywords:
-------------------------------------------------------+--------------------
`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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8292> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC