boostorg / boostorg/histogram

Improve numerical accuracy of circular axis

Ouverte
#380 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
C++
Étoiles
334
Forks
76
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

The `if (options_type::test(option::circular))` inside `index_type index(value_type x)` and `value_type value(real_index_type i)` reminds me of when I was dealing with periodic argument reduction in a simulator+monitor program (every ms PC sends sin(A*t+B) and receives actual value to&from a chip through UDP, t can be as large as several days). There should be some high precision functions in boost.core/utility/utilities/tool/tools/toolbox/... and we just need to find them.
https://en.cppreference.com/w/cpp/numeric/lerp
https://stackoverflow.com/questions/64058564/single-precision-argument-reduction-for-trigonometric-functions-in-c
```C++
{
// using A = axis::variable; // using double solves the errors
using A = axis::variable;
auto a = A({
1.,
1e+8,
2e+8,
});
BOOST_TEST_EQ(a.index(1e8), 1);
BOOST_TEST_EQ(a.index(2e8), 0); // test 'a.index(2e8) == 0' ('-1' == '0') failed
BOOST_TEST_EQ(a.index(4e8), 0); // test 'a.index(4e8) == 0' ('-1' == '0') failed
}
{
// using A = axis::variable; // using double solves the errors
using A = axis::variable;
auto a = A({
-2e+8,
-1e+8,
-1.,
});
BOOST_TEST_EQ(a.index(-1e8), 1);
BOOST_TEST_EQ(a.index(-2e8), 0);
BOOST_TEST_EQ(a.index(-4e8), 1); // test 'a.index(-4e8) == 1' ('0' == '1') failed
}
return boost::report_errors();
```

_Originally posted by @jhcarl0814 in https://github.com/boostorg/histogram/issues/372#issuecomment-1364386000_

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.