Skip to content

Commit 5afd187

Browse files
committed
Add quasi_exact tag
- like power but intended for slightly different operation
1 parent 9c77f1d commit 5afd187

16 files changed

Lines changed: 375 additions & 33 deletions

include/cnl/_impl/scaled/power/is_same_tag_family.h renamed to include/cnl/_impl/scaled/is_same_tag_family.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
#if !defined(CNL_IMPL_SCALED_POWER_IS_SAME_TAG_FAMILY_H)
88
#define CNL_IMPL_SCALED_POWER_IS_SAME_TAG_FAMILY_H
99

10-
#include "../../custom_operator/is_same_tag_family.h"
10+
#include "../custom_operator/is_same_tag_family.h"
1111
#include "is_scaled_tag.h"
1212

1313
#include <type_traits>
1414

1515
/// compositional numeric library
1616
namespace cnl {
1717
namespace _impl {
18-
template<int Exponent1, int Radix1, int Exponent2, int Radix2>
19-
struct is_same_tag_family<power<Exponent1, Radix1>, power<Exponent2, Radix2>>
18+
template<scaled_tag Tag1, scaled_tag Tag2>
19+
struct is_same_tag_family<Tag1, Tag2>
2020
: std::true_type {
2121
};
2222
}

include/cnl/_impl/scaled/is_tag.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// Copyright John McFarlane 2019.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(CNL_IMPL_SCALED_QUASI_EXACT_IS_TAG_H)
8+
#define CNL_IMPL_SCALED_QUASI_EXACT_IS_TAG_H
9+
10+
#include "../custom_operator/tag.h"
11+
#include "is_scaled_tag.h"
12+
13+
/// compositional numeric library
14+
namespace cnl {
15+
template<scaled_tag Tag>
16+
inline constexpr auto is_tag<Tag> = true;
17+
}
18+
19+
#endif // CNL_IMPL_SCALED_QUASI_EXACT_IS_TAG_H

include/cnl/_impl/scaled/power.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#if !defined(CNL_IMPL_SCALED_POWER_H)
88
#define CNL_IMPL_SCALED_POWER_H
99

10+
#include "is_same_tag_family.h"
11+
#include "is_scaled_tag.h"
12+
#include "is_tag.h"
1013
#include "power/binary_operator.h"
1114
#include "power/convert_operator.h"
1215
#include "power/definition.h"
1316
#include "power/inc_dec_operator.h"
14-
#include "power/is_same_tag_family.h"
1517
#include "power/is_scaled_tag.h"
16-
#include "power/is_tag.h"
1718
#include "power/unary_operator.h"
1819

1920
#endif // CNL_IMPL_SCALED_POWER_H

include/cnl/_impl/scaled/power/convert_operator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "../../num_traits/scale.h"
1616
#include "../../power_value.h"
1717
#include "../../scaled_integer/definition.h"
18-
#include "is_same_tag_family.h"
1918

2019
/// compositional numeric library
2120
namespace cnl {

include/cnl/_impl/scaled/power/definition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace cnl {
1919
/// \tparam Exponent the exponent used to scale the integer value; defaults to 0
2020
/// \tparam Radix the base used to scale the integer value; defaults to 2
2121
///
22-
/// \sa scaled_integer
22+
/// \sa scaled_integer, quasi_exact
2323

2424
template<int Exponent, int Radix>
2525
struct power {

include/cnl/_impl/scaled/power/is_tag.h

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
// Copyright John McFarlane 2021.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(CNL_IMPL_SCALED_QUASI_EXACT_H)
8+
#define CNL_IMPL_SCALED_QUASI_EXACT_H
9+
10+
#include "is_same_tag_family.h"
11+
#include "is_scaled_tag.h"
12+
#include "is_tag.h"
13+
#include "quasi_exact/binary_operator.h"
14+
#include "quasi_exact/convert_operator.h"
15+
#include "quasi_exact/definition.h"
16+
#include "quasi_exact/inc_dec_operator.h"
17+
#include "quasi_exact/is_scaled_tag.h"
18+
#include "quasi_exact/unary_operator.h"
19+
20+
#endif // CNL_IMPL_SCALED_QUASI_EXACT_H
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Copyright John McFarlane 2021.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(CNL_IMPL_SCALED_QUASI_EXACT_BINARY_OPERATOR_H)
8+
#define CNL_IMPL_SCALED_QUASI_EXACT_BINARY_OPERATOR_H
9+
10+
#include "../../custom_operator/op.h"
11+
#include "../../custom_operator/definition.h"
12+
#include "../power/binary_operator.h"
13+
#include "declaration.h"
14+
15+
/// compositional numeric library
16+
namespace cnl {
17+
template<_impl::binary_op Operator, typename Lhs, int LhsExponent, int RhsExponent, typename Rhs, int Radix>
18+
struct custom_operator<
19+
Operator,
20+
op_value<Lhs, quasi_exact<LhsExponent, Radix>>,
21+
op_value<Rhs, quasi_exact<RhsExponent, Radix>>>
22+
: custom_operator<
23+
Operator,
24+
op_value<Lhs, power<LhsExponent, Radix>>,
25+
op_value<Rhs, power<RhsExponent, Radix>>> {
26+
};
27+
}
28+
29+
#endif // CNL_IMPL_SCALED_QUASI_EXACT_BINARY_OPERATOR_H
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
// Copyright John McFarlane 2021.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(CNL_IMPL_SCALED_QUASI_EXACT_CONVERT_OPERATOR_H)
8+
#define CNL_IMPL_SCALED_QUASI_EXACT_CONVERT_OPERATOR_H
9+
10+
#include "../../../floating_point.h"
11+
#include "../../../fraction.h"
12+
#include "../../custom_operator/native_tag.h"
13+
#include "../../num_traits/fixed_width_scale.h"
14+
#include "../../num_traits/scale.h"
15+
#include "../../power_value.h"
16+
#include "../../scaled_integer/definition.h"
17+
18+
/// compositional numeric library
19+
namespace cnl {
20+
template<number Src, int SrcExponent, number Dest, int DestExponent, int Radix>
21+
struct custom_operator<
22+
_impl::convert_op,
23+
op_value<Src, quasi_exact<SrcExponent, Radix>>,
24+
op_value<Dest, quasi_exact<DestExponent, Radix>>>
25+
: custom_operator<
26+
_impl::convert_op,
27+
op_value<Src, power<SrcExponent, Radix>>,
28+
op_value<Dest, power<DestExponent, Radix>>> {
29+
};
30+
31+
// shims between equivalent tags
32+
template<typename Input, typename Result, int DestExponent, int DestRadix>
33+
struct custom_operator<
34+
_impl::convert_op,
35+
op_value<Input>,
36+
op_value<Result, quasi_exact<DestExponent, DestRadix>>>
37+
: custom_operator<
38+
_impl::convert_op,
39+
op_value<Input>,
40+
op_value<Result, power<DestExponent, DestRadix>>> {
41+
};
42+
43+
template<typename Input, int SrcExponent, int SrcRadix, typename Result>
44+
struct custom_operator<
45+
_impl::convert_op,
46+
op_value<Input, quasi_exact<SrcExponent, SrcRadix>>,
47+
op_value<Result>>
48+
: custom_operator<
49+
_impl::convert_op,
50+
op_value<Input, power<SrcExponent, SrcRadix>>,
51+
op_value<Result>> {
52+
};
53+
}
54+
55+
#endif // CNL_IMPL_SCALED_QUASI_EXACT_CONVERT_OPERATOR_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// Copyright John McFarlane 2021.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file ../LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(CNL_IMPL_SCALED_QUASI_EXACT_DECLARATION_H)
8+
#define CNL_IMPL_SCALED_QUASI_EXACT_DECLARATION_H
9+
10+
/// compositional numeric library
11+
namespace cnl {
12+
template<int Exponent = 0, int Radix = 2>
13+
struct quasi_exact;
14+
}
15+
16+
#endif // CNL_IMPL_SCALED_QUASI_EXACT_DECLARATION_H

0 commit comments

Comments
 (0)