Skip to content

Commit 75b424f

Browse files
committed
Document exceptions properly
1 parent 6ae8081 commit 75b424f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

arby/include/arby/arby.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ namespace com::saxbophone::arby {
116116
* @brief Arbitrary-precision unsigned integer type
117117
* @note `std::numeric_limits<Uint>` is specialised such that most of the
118118
* members of that type are implemented to describe the traits of this type.
119-
* @note Exceptions include any members which describe a finite number of digits
120-
* or a maximmum value, neither of which apply to this type as it is unbounded.
119+
* @note Exceptions include any members of std::numeric_limits<> which
120+
* describe a finite number of digits or a maximmum value, neither of which
121+
* apply to this type as it is unbounded.
122+
* @exception std::logic_error may be thrown from most methods when the
123+
* result of an operation leaves a Uint object with leading zero digits in
124+
* its internal representation. Such cases are the result of bugs in this
125+
* code and should be reported as such.
121126
*/
122127
class Uint {
123128
private:
@@ -184,7 +189,8 @@ namespace com::saxbophone::arby {
184189
* @brief Constructor-like static method, creates Uint from floating point value
185190
* @returns Uint with the value of the given float, with the fractional part truncated off
186191
* @param value Positive floating point value to initialise with
187-
* @throws std::domain_error when `value < 0`
192+
* @throws std::domain_error when `value < 0` or when `value` is not a
193+
* finite number.
188194
*/
189195
static Uint from_float(long double value) {
190196
// prevent initialising from negative values
@@ -371,6 +377,7 @@ namespace com::saxbophone::arby {
371377
* @details Subtracts other value from this Uint and assigns the result to self
372378
* @param rhs value to subtract from this Uint
373379
* @returns resulting object after subtraction-assignment
380+
* @throws std::underflow_error when rhs is bigger than this
374381
*/
375382
constexprvector Uint& operator-=(Uint rhs) {
376383
// TODO: detect underflow early?
@@ -408,6 +415,7 @@ namespace com::saxbophone::arby {
408415
* @brief Subtraction operator for Uint
409416
* @param lhs,rhs operands for the subtraction
410417
* @returns result of lhs - rhs
418+
* @throws std::underflow_error when rhs is bigger than lhs
411419
*/
412420
friend constexprvector Uint operator-(Uint lhs, const Uint& rhs) {
413421
lhs -= rhs; // reuse compound assignment
@@ -493,6 +501,7 @@ namespace com::saxbophone::arby {
493501
* @brief division and modulo all-in-one, equivalent to C/C++ div() and Python divmod()
494502
* @param lhs,rhs operands for the division/modulo operation
495503
* @returns tuple of {quotient, remainder}
504+
* @throws std::domain_error when rhs is zero
496505
*/
497506
static constexprvector std::tuple<Uint, Uint> divmod(const Uint& lhs, const Uint& rhs) {
498507
// division by zero is undefined
@@ -533,6 +542,7 @@ namespace com::saxbophone::arby {
533542
* @note This implements floor-division, returning the quotient only
534543
* @param rhs value to divide this Uint by
535544
* @returns resulting object after division-assignment
545+
* @throws std::domain_error when rhs is zero
536546
*/
537547
constexprvector Uint& operator/=(const Uint& rhs) {
538548
Uint quotient = *this / rhs; // uses friend /operator
@@ -557,6 +567,7 @@ namespace com::saxbophone::arby {
557567
* @note This returns the modulo/remainder of the division operation
558568
* @param rhs value to modulo-divide this Uint by
559569
* @returns resulting object after modulo-assignment
570+
* @throws std::domain_error when rhs is zero
560571
*/
561572
constexprvector Uint& operator%=(const Uint& rhs) {
562573
Uint remainder = *this % rhs; // uses friend %operator
@@ -569,6 +580,7 @@ namespace com::saxbophone::arby {
569580
* @note This implements modulo-division, returning the remainder only
570581
* @param lhs,rhs operands for the division
571582
* @returns remainder of lhs / rhs
583+
* @throws std::domain_error when rhs is zero
572584
*/
573585
friend constexprvector Uint operator%(Uint lhs, const Uint& rhs) {
574586
Uint remainder;

0 commit comments

Comments
 (0)