faster axis integer value method (#220)

This commit is contained in:
Hans Dembinski 2019-09-27 01:09:25 +02:00 committed by GitHub
parent 6b767cc2aa
commit b4298d6857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -130,9 +130,10 @@ public:
/// Return value for index argument.
value_type value(local_index_type i) const noexcept {
if (!options_type::test(option::circular)) {
if (!options_type::test(option::circular) &&
std::is_floating_point<value_type>::value) {
if (i < 0) return detail::lowest<value_type>();
if (i > size()) { return detail::highest<value_type>(); }
if (i > size()) return detail::highest<value_type>();
}
return min_ + i;
}

View File

@ -61,8 +61,8 @@ int main() {
// axis::integer with int type
{
axis::integer<int> a{-1, 2};
BOOST_TEST_EQ(a.bin(-2), (std::numeric_limits<int>::min)());
BOOST_TEST_EQ(a.bin(4), (std::numeric_limits<int>::max)());
BOOST_TEST_EQ(a.bin(-2), -3);
BOOST_TEST_EQ(a.bin(4), 3);
BOOST_TEST_EQ(a.index(-10), -1);
BOOST_TEST_EQ(a.index(-2), -1);
BOOST_TEST_EQ(a.index(-1), 0);