- Add default constructor necessary for use with STL containers.
- Add division and modulus operators which are used routinely.
Details
- Reviewers
deadalnix freetrader - Group Reviewers
Restricted Project - Commits
- rSTAGING1de8caa74e45: Add default construct, and several ops, to Amount class
rABC1de8caa74e45: Add default construct, and several ops, to Amount class
make VERBOSE=1 check
Diff Detail
- Repository
- rABC Bitcoin ABC
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
src/amount.h | ||
---|---|---|
85 ↗ | (On Diff #1392) | The return value seems off. However, given that T has no units associated with it (or unknown units), I think this is correct. |
src/amount.h | ||
---|---|---|
14 ↗ | (On Diff #1392) | This guy should have been removed. |
73 ↗ | (On Diff #1392) | Why double ? I don't think we should use floating point implicitely. Also do not use C style cast, use C++ constructors. |
75 ↗ | (On Diff #1392) | I think you should just use the delete trick. |
77 ↗ | (On Diff #1392) | Division is not commutative, so you can make this a member function rather than a friend one. |
80 ↗ | (On Diff #1392) | An amount divided by an amount is unitless. |
85 ↗ | (On Diff #1392) | dito. |
src/test/amount_tests.cpp | ||
72 ↗ | (On Diff #1392) | This should test negative values as well. |
src/amount.h | ||
---|---|---|
73 ↗ | (On Diff #1392) | I'll change the cast style. However, unless this is explicitly cast, it will be integer division and truncate: int main(void) { int64_t a = 10; int64_t b = 20; std::cout << "Output: " << a / b << std::endl; std::cout << "Output: " << double(a) / double(b) << std::endl; } > g++ test.cpp -o test && ./test Output: 0 Output: 0.5 |
80 ↗ | (On Diff #1392) | This is modulo though, which has the units of the original thing that was left-over from the division. |
- Remove is_integral template useage
- Use 'delete' to ensure operations against double are invalid
- Update tests
src/amount.h | ||
---|---|---|
82 ↗ | (On Diff #1408) | I don't know what you're telling me. We need both the int and the int64_t (which is the next line) for the delete trick to work. As for the return value, as stated previously, a remainder has the units of the dividend. |
src/amount.h | ||
---|---|---|
82 ↗ | (On Diff #1408) | Ha yes sorry, you are right. |
src/amount.h | ||
---|---|---|
79 ↗ | (On Diff #1414) | This should return an int64_t or just not exist. |
src/amount.h | ||
---|---|---|
79 ↗ | (On Diff #1414) | Sorry but you were right, this is an amount. The formula is A = Q*B + R So R is the same type as A, which is an amount. However, I'm not sure this function should exist at all. |