Design question SafeFloat
Hi,
I'm working in simplifying safe_float to prepare it for future review.
For now I'm focusing in a C++17 compatible version.
Currently safefloat receives 2 template parameters:
template
On 7/26/18 8:25 PM, Damian Vicino via Boost wrote:
Hi, I'm working in simplifying safe_float to prepare it for future review.
For now I'm focusing in a C++17 compatible version.
Currently safefloat receives 2 template parameters:
template
class safe_float ... Where FP is the floating point value being made "safe", float, double, long double ... and P is a Policy of what to check and how to react.
It might be helpful to look at how safe numerics does it. Robert Ramey
Hi Robert,
Thanks for the comment, I started following whats on safe_numerics, but I
feel it gets too complicated to use in the case of floating point where
there is so many policy combinations I want to allow. I got the feeling
something easier can be built to handle this particular case.
However, I'm exploring alternatives, if I cannot find a simple elegant
solution I will go back to similar approach to the one used in
safe_numerics.
2018-07-27 10:05 GMT-04:00 Robert Ramey via Boost
On 7/26/18 8:25 PM, Damian Vicino via Boost wrote:
Hi, I'm working in simplifying safe_float to prepare it for future review.
For now I'm focusing in a C++17 compatible version.
Currently safefloat receives 2 template parameters:
template
class safe_float ... Where FP is the floating point value being made "safe", float, double, long double ... and P is a Policy of what to check and how to react.
It might be helpful to look at how safe numerics does it.
Robert Ramey
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman /listinfo.cgi/boost
AMDG On 07/26/2018 09:25 PM, Damian Vicino via Boost wrote:
I'm working in simplifying safe_float to prepare it for future review.
For now I'm focusing in a C++17 compatible version.
Currently safefloat receives 2 template parameters:
template
class safe_float ... Where FP is the floating point value being made "safe", float, double, long double ... and P is a Policy of what to check and how to react.
<snip> These are the options I'm considering
1) define typenames for each flag and assign them tuple of affected operations
class addition; <snip>
template<typename R> struct policy_x { using reporter=R; using overflow=tuple<addition>; <snip> };
2) define typename by operation, passing class with constexprs of flags being evaluated
struct empty_check{ static constexpr bool check_overflow=false; <snip> };
<snip>
3) similar to 2, but using true_type, and false_type in place of constexpr variables. <snip> 4) other options?
What about doing this the old-fashioned way: constexpr check_policy_t empty_check = 0; constexpr check_policy_t check_underflow = 0x1; constexpr check_policy_t check_overflow = 0x2; ... // with a bit of syntactic sugar: struct operation_id { check_policy_t offset; constexpr check_policy_t operator=(check_policy_t value) const { return offset * value; } }; constexpr operation_id addition=0x1, subtraction=0x100, multiplication=0x10000 ...; // Usage: addition=check_overflow|subtraction=empty_check In Christ, Steven Watanabe
Hi Steven,
Thats kind of what I would like to have, I was wondering of something like
that using "enum class" for type_safety would work.
I will give it a try and see how it goes.
Thanks for the comment.
Damian
2018-07-27 14:38 GMT-04:00 Steven Watanabe via Boost
AMDG
On 07/26/2018 09:25 PM, Damian Vicino via Boost wrote:
I'm working in simplifying safe_float to prepare it for future review.
For now I'm focusing in a C++17 compatible version.
Currently safefloat receives 2 template parameters:
template
class safe_float ... Where FP is the floating point value being made "safe", float, double, long double ... and P is a Policy of what to check and how to react.
<snip> These are the options I'm considering
1) define typenames for each flag and assign them tuple of affected operations
class addition; <snip>
template<typename R> struct policy_x { using reporter=R; using overflow=tuple<addition>; <snip> };
2) define typename by operation, passing class with constexprs of flags being evaluated
struct empty_check{ static constexpr bool check_overflow=false; <snip> };
<snip>
3) similar to 2, but using true_type, and false_type in place of constexpr variables. <snip> 4) other options?
What about doing this the old-fashioned way:
constexpr check_policy_t empty_check = 0; constexpr check_policy_t check_underflow = 0x1; constexpr check_policy_t check_overflow = 0x2; ...
// with a bit of syntactic sugar: struct operation_id { check_policy_t offset; constexpr check_policy_t operator=(check_policy_t value) const { return offset * value; } };
constexpr operation_id addition=0x1, subtraction=0x100, multiplication=0x10000 ...;
// Usage: addition=check_overflow|subtraction=empty_check
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/ mailman/listinfo.cgi/boost
participants (3)
-
Damian Vicino
-
Robert Ramey
-
Steven Watanabe