Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit 992b2ca

Browse files
Merge pull request #258 from johnmcfarlane/docs
Docs
2 parents 20911bd + 3d473a6 commit 992b2ca

File tree

4 files changed

+39
-76
lines changed

4 files changed

+39
-76
lines changed

doc/Doxyfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ INPUT = \
2020
../include/sg14/auxiliary/elastic_fixed_point.h \
2121
../include/sg14/auxiliary/elastic_integer.h \
2222
../include/sg14/auxiliary/multiprecision.h \
23+
../include/sg14/auxiliary/numeric.h \
24+
../include/sg14/auxiliary/overflow.h \
25+
../include/sg14/auxiliary/precise_integer.h \
26+
../include/sg14/auxiliary/safe_integer.h \
2327
../include/sg14/fixed_point \
28+
../include/sg14/bits/fixed_point_arithmetic.h \
2429
../include/sg14/bits/fixed_point_extras.h \
2530
../include/sg14/bits/fixed_point_math.h \
2631
../include/sg14/bits/fixed_point_make.h \
2732
../include/sg14/bits/fixed_point_named.h \
2833
../include/sg14/bits/fixed_point_operators.h \
2934
../include/sg14/bits/fixed_point_common_type.h \
3035
../include/sg14/bits/fixed_point_type.h \
31-
../include/sg14/cstdint \
32-
../include/sg14/limits \
33-
../include/sg14/type_traits \
36+
../include/sg14/bits/type_traits.h \
37+
../include/sg14/bits/number_base.h \
38+
../include/sg14/bits/config.h \
39+
../include/sg14/bits/common.h \
40+
../include/sg14/bits/limits.h \
41+
../include/sg14/num_traits.h \
3442
index.md
3543
EXCLUDE_SYMBOLS = \
3644
sg14::_*

doc/gh-pages

Submodule gh-pages updated 118 files

doc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Header, [sg14/fixed_point](@ref fixed_point), defines class template, [fixed_poi
2020
* operator overloads that interface [fixed_point](@ref sg14::fixed_point) with other numeric types;
2121
* a set of function templates, (e.g. [multiply](@ref sg14::multiply)), for fine-grain control.
2222

23-
Header, [sg14/cstdint](@ref cstdint), contains additions (such as [set_width](@ref sg14::set_width))
23+
Header, [sg14/num_traits](@ref num_traits), contains additions (such as [set_digits](@ref sg14::set_digits))
2424
that support widening of arithmetic types in order to deal with precision loss.
2525

2626
Auxiliary modules:

src/single_header/fixed_point.h

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <stdexcept>
2020
#include <type_traits>
2121

22-
2322
namespace sg14 {
2423
namespace _impl {
2524
template<class ... T>
@@ -772,17 +771,17 @@ namespace sg14 {
772771
class Operator, class Lhs, class RhsDerived, class RhsRep,
773772
enable_if_t <precedes<Lhs, RhsDerived>::value, std::nullptr_t> = nullptr>
774773
constexpr auto operate(const Lhs& lhs, const number_base<RhsDerived, RhsRep>& rhs, Operator op)
775-
-> decltype(op(lhs, to_rep(static_cast<const RhsDerived&>(rhs))))
774+
-> decltype(op(lhs, static_cast<Lhs>(static_cast<const RhsDerived&>(rhs))))
776775
{
777-
return op(lhs, to_rep(static_cast<const RhsDerived&>(rhs)));
776+
return op(lhs, static_cast<Lhs>(static_cast<const RhsDerived&>(rhs)));
778777
}
779778
template<
780779
class Operator, class LhsDerived, class LhsRep, class Rhs,
781780
enable_if_t <precedes<Rhs, LhsDerived>::value, std::nullptr_t> = nullptr>
782781
constexpr auto operate(const number_base<LhsDerived, LhsRep>& lhs, const Rhs& rhs, Operator op)
783-
-> decltype(op(to_rep(static_cast<const LhsDerived&>(lhs)), rhs))
782+
-> decltype(op(static_cast<Rhs>(static_cast<const LhsDerived&>(lhs)), rhs))
784783
{
785-
return op(to_rep(static_cast<const LhsDerived&>(lhs)), rhs);
784+
return op(static_cast<Rhs>(static_cast<const LhsDerived&>(lhs)), rhs);
786785
}
787786
template<
788787
class Operator, class Lhs, class RhsDerived, class RhsRep,
@@ -1268,6 +1267,13 @@ namespace sg14 {
12681267
using result_type = elastic_integer<RhsDigits, typename make_signed<RhsNarrowest>::type>;
12691268
return result_type::from_data(-static_cast<result_type>(rhs).data());
12701269
}
1270+
template<int RhsDigits, class RhsNarrowest>
1271+
constexpr auto operator+(const elastic_integer<RhsDigits, RhsNarrowest>& rhs)
1272+
-> elastic_integer<RhsDigits, typename make_signed<RhsNarrowest>::type>
1273+
{
1274+
using result_type = elastic_integer<RhsDigits, typename make_signed<RhsNarrowest>::type>;
1275+
return result_type::from_data(static_cast<result_type>(rhs).data());
1276+
}
12711277
}
12721278
namespace std {
12731279
template<int LhsDigits, class LhsNarrowest, int RhsDigits, class RhsNarrowest>
@@ -1831,15 +1837,7 @@ namespace std {
18311837
};
18321838
template<class LhsRep, int LhsExponent, class RhsRep, int RhsExponent>
18331839
struct common_type<sg14::fixed_point<LhsRep, LhsExponent>, sg14::fixed_point<RhsRep, RhsExponent>> {
1834-
using _result_rep = typename std::common_type<LhsRep, RhsRep>::type;
1835-
static constexpr int _capacity = std::numeric_limits<_result_rep>::digits;
1836-
static constexpr int _ideal_max_top = sg14::_impl::max(
1837-
sg14::fixed_point<LhsRep, LhsExponent>::integer_digits,
1838-
sg14::fixed_point<RhsRep, RhsExponent>::integer_digits);
1839-
static constexpr int _ideal_exponent = sg14::_impl::min(LhsExponent, RhsExponent);
1840-
static constexpr int _exponent = ((_ideal_max_top-_ideal_exponent)<=_capacity) ? _ideal_exponent :
1841-
_ideal_max_top-_capacity;
1842-
using type = sg14::fixed_point<_result_rep, _exponent>;
1840+
using type = sg14::fixed_point<sg14::_impl::common_type_t<LhsRep, RhsRep>, sg14::_impl::min(LhsExponent, RhsExponent)>;
18431841
};
18441842
}
18451843
namespace sg14 {
@@ -1888,54 +1886,6 @@ namespace sg14 {
18881886
{
18891887
return _impl::fp::operate<_impl::fp::division_arithmetic_operator_tag>(lhs, rhs, _impl::divide_tag);
18901888
}
1891-
template<class Rep, int Exponent>
1892-
constexpr auto operator==(
1893-
const fixed_point <Rep, Exponent>& lhs,
1894-
const fixed_point <Rep, Exponent>& rhs)
1895-
-> decltype(lhs.data()==rhs.data())
1896-
{
1897-
return lhs.data()==rhs.data();
1898-
}
1899-
template<class Rep, int Exponent>
1900-
constexpr auto operator!=(
1901-
const fixed_point <Rep, Exponent>& lhs,
1902-
const fixed_point <Rep, Exponent>& rhs)
1903-
-> decltype(lhs.data()!=rhs.data())
1904-
{
1905-
return lhs.data()!=rhs.data();
1906-
}
1907-
template<class Rep, int Exponent>
1908-
constexpr auto operator>(
1909-
const fixed_point <Rep, Exponent>& lhs,
1910-
const fixed_point <Rep, Exponent>& rhs)
1911-
-> decltype(lhs.data()>rhs.data())
1912-
{
1913-
return lhs.data()>rhs.data();
1914-
}
1915-
template<class Rep, int Exponent>
1916-
constexpr auto operator<(
1917-
const fixed_point <Rep, Exponent>& lhs,
1918-
const fixed_point <Rep, Exponent>& rhs)
1919-
-> decltype(lhs.data()<rhs.data())
1920-
{
1921-
return lhs.data()<rhs.data();
1922-
}
1923-
template<class Rep, int Exponent>
1924-
constexpr auto operator>=(
1925-
const fixed_point <Rep, Exponent>& lhs,
1926-
const fixed_point <Rep, Exponent>& rhs)
1927-
-> decltype(lhs.data()>=rhs.data())
1928-
{
1929-
return lhs.data()>=rhs.data();
1930-
}
1931-
template<class Rep, int Exponent>
1932-
constexpr auto operator<=(
1933-
const fixed_point <Rep, Exponent>& lhs,
1934-
const fixed_point <Rep, Exponent>& rhs)
1935-
-> decltype(lhs.data()<=rhs.data())
1936-
{
1937-
return lhs.data()<=rhs.data();
1938-
}
19391889
namespace _fixed_point_operators_impl {
19401890
template<class Lhs, class Rhs>
19411891
constexpr bool is_heterogeneous() {
@@ -1952,6 +1902,12 @@ namespace sg14 {
19521902
{
19531903
return op(static_cast<_impl::common_type_t<Lhs, Rhs>>(lhs), static_cast<_impl::common_type_t<Lhs, Rhs>>(rhs));
19541904
};
1905+
template<class Operator, class Rep, int Exponent, class = _impl::enable_if_t<Operator::is_comparison>>
1906+
constexpr auto operate(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs, Operator op)
1907+
-> decltype(op(lhs.data(), rhs.data()))
1908+
{
1909+
return op(lhs.data(), rhs.data());
1910+
};
19551911
}
19561912
template<
19571913
class LhsRep, int LhsExponent,
@@ -2127,7 +2083,6 @@ namespace sg14 {
21272083
return fixed_point<LhsRep, LhsExponent-RhsValue>::from_data(lhs.data());
21282084
}
21292085
}
2130-
21312086
namespace sg14 {
21322087
namespace _impl {
21332088
template<class Rep, int Exponent>
@@ -2281,7 +2236,7 @@ namespace std {
22812236
}
22822237
static constexpr _value_type round_error() noexcept
22832238
{
2284-
return static_cast<_value_type>(.5);
2239+
return _value_type::from_data(_rep{0});
22852240
}
22862241
static constexpr _value_type infinity() noexcept
22872242
{
@@ -2815,7 +2770,7 @@ namespace sg14 {
28152770
}
28162771
namespace _impl {
28172772
template<class OverflowTag, class OperatorTag, class LhsRep, class RhsRep, class = enable_if_t<OperatorTag::is_arithmetic>>
2818-
constexpr auto operate_common_policy(
2773+
constexpr auto operate_common_tag(
28192774
OverflowTag,
28202775
OperatorTag,
28212776
const safe_integer<LhsRep, OverflowTag>& lhs,
@@ -2825,7 +2780,7 @@ namespace sg14 {
28252780
return make_safe_integer<OverflowTag>(_overflow_impl::operate<OverflowTag, OperatorTag>()(lhs.data(), rhs.data()));
28262781
}
28272782
template<class OverflowTag, class OperatorTag, class LhsRep, class RhsRep, class = enable_if_t<OperatorTag::is_comparison>>
2828-
constexpr auto operate_common_policy(
2783+
constexpr auto operate_common_tag(
28292784
OverflowTag,
28302785
OperatorTag,
28312786
const safe_integer<LhsRep, OverflowTag>& lhs,
@@ -2834,14 +2789,14 @@ namespace sg14 {
28342789
{
28352790
return _overflow_impl::operate<OverflowTag, OperatorTag>()(lhs.data(), rhs.data());
28362791
}
2837-
template<class OperatorTag, class LhsRep, class LhsPolicy, class RhsRep, class RhsPolicy>
2792+
template<class OperatorTag, class LhsRep, class LhsTag, class RhsRep, class RhsTag>
28382793
constexpr auto operate(
2839-
const safe_integer<LhsRep, LhsPolicy>& lhs,
2840-
const safe_integer<RhsRep, RhsPolicy>& rhs,
2794+
const safe_integer<LhsRep, LhsTag>& lhs,
2795+
const safe_integer<RhsRep, RhsTag>& rhs,
28412796
OperatorTag operator_tag)
2842-
-> decltype(operate_common_policy(common_type_t<LhsPolicy, RhsPolicy>{}, operator_tag, lhs, rhs))
2797+
-> decltype(operate_common_tag(common_type_t<LhsTag, RhsTag>{}, operator_tag, lhs, rhs))
28432798
{
2844-
return operate_common_policy(common_type_t<LhsPolicy, RhsPolicy>{}, operator_tag, lhs, rhs);
2799+
return operate_common_tag(common_type_t<LhsTag, RhsTag>{}, operator_tag, lhs, rhs);
28452800
}
28462801
}
28472802
template <class LhsRep, class LhsOverflowTag, class RhsRep, class RhsOverflowTag> constexpr auto operator >> (const safe_integer<LhsRep, LhsOverflowTag>& lhs, const safe_integer<RhsRep, RhsOverflowTag>& rhs) -> safe_integer<LhsRep, LhsOverflowTag> { return lhs.data() >> rhs.data(); } template <class Lhs, class RhsRep, class RhsOverflowTag, _impl::enable_if_t<std::is_fundamental<Lhs>::value, int> dummy = 0> constexpr auto operator >> (const Lhs& lhs, const safe_integer<RhsRep, RhsOverflowTag>& rhs) -> Lhs { return lhs >> rhs.data(); } template <class LhsRep, class LhsOverflowTag, class Rhs, _impl::enable_if_t<std::is_fundamental<Rhs>::value, int> dummy = 0> constexpr auto operator >> (const safe_integer<LhsRep, LhsOverflowTag>& lhs, const Rhs& rhs) -> safe_integer<LhsRep, LhsOverflowTag> { return safe_integer<LhsRep, LhsOverflowTag>(lhs.data() >> rhs); };

0 commit comments

Comments
 (0)