-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support boost::rational
as value type for axis::regular
#337
Labels
Comments
Related #336 |
Prototype for experimenting #include <boost/histogram.hpp>
#include <boost/histogram/ostream.hpp>
#include <boost/rational.hpp>
#include <iostream>
int main() {
namespace bh = boost::histogram;
struct axis {
using value_type = boost::rational<int>;
using index_type = bh::axis::index_type;
index_type num_;
value_type offset_;
value_type scale_;
axis(index_type n, value_type a, value_type b) :
num_{n}, offset_{a}, scale_{rat{n} / (b - a)} {}
index_type index(const value_type& x) const {
const auto i = boost::rational_cast<index_type>(scale_ * (x - offset_));
return i >= -1 ? (i < num_ ? i : num_) : -1;
}
value_type value(index_type i) const {
return i / scale_ + offset_;
}
index_type size() const { return num_; }
static constexpr auto options() { return bh::axis::option::underflow | bh::axis::option::overflow; }
};
auto h = bh::make_histogram(axis{10, 0, 5});
h(-1);
h(1);
h(2);
std::cout << h << std::endl;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This currently triggers a static_assert, but should be supported.
The text was updated successfully, but these errors were encountered: