Hi,
I looking for some design advice.
The context:
- I'm revisiting SafeFloat after some time and, while doing so, I'm
rethinking all the decisions from the past. Idea is to sent for review in
the following months.
- The goal of the library is being a drop-in replacement for float, that
adds checks to floating point operations and reports when a check failed.
Without SafeFloat, someone could write something like this:
#include <iostream>
#include <limits>
#include <cfenv>
using namespace std;
int main(){
float a = 1.0f;
float b = numeric_limits<float>::max();
feclearexcept(FE_ALL_EXCEPT);
float c = a/b;
if(fetestexcept(FE_UNDERFLOW)) { cout << "underflow result\n"; }
}
What I expect when using safe_float is to declare upfront "what checks" I
care about, "what operations" to check, and "what to do when a check fails".
Some intention examples:
- I would like to check there was no "overflow_to_infinite" in "addition
operations", otherwise I "throw exception"..
- I would like to check there was no "division by zero" in "division",
otherwise I will "log to cerr and ignore it".
- I would like to check there was no "inexact" "addition", otherwise I
return an boost::unexpected.
I have at least 5 things to check (there is 5 flags in c++11::fenv). I have
at least 4 places to check (+/-/*//) and I want to keep what to do about it
customizable.
In addition, sometimes I want to check multiple things "overflow and
underflow", etc...
So, the question is how the user can pass all that information to the type
and it doesn't look as horrible nonsense.
My original option was:
int main(){
using CHECK = compose_policy