boostorg / boostorg/safe_numerics
Consider providing an abs(boost::safe_numerics::safe) overload
- Dominant language
- C++
- Stars
- 222
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
The lack of such an overload has two drawbacks:
1. If one currently has code like:
```
int main()
{
using I = boost::safe_numerics::safe;
I x = INT32_MAX;
I y = abs(x)+abs(x); // silently overflows
std::cout << y; // prints -2
}
```
then the overflow is not detected. If SafeNumerics provided its own `abs` overload for `safe` returning a `safe`, then the overflow could be detected and signaled.
2. If one currently has perfectly valid code like:
```
using I = int32_t;
using std::abs;
I x = 3, y = abs(x);
```
then changing the first line to `using I = boost::safe_numerics::safe;` makes the code ill-formed, due to the ambiguity resulting from the fact that `boost::safe_numerics::safe` is willing to convert to the parameter type of multiple `std::abs` overloads.
Contributor guide
No contributing guide indexed for this repository
Research direction
No source files or tests are named. Start by locating the definition of boost::safe_numerics::safe and its existing operator overloads, then inspect how std::abs is selected for safe values. Done means valid abs usage compiles with safe and overflow in the example is detected, with focused tests covering both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100