File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -126,13 +126,23 @@ class RFL_API Generic {
126126 }
127127
128128 // / Casts the underlying value to a double or returns an rfl::Error, if the
129- // / underlying value is not a double.
129+ // / underlying value is not a number or the conversion would result in loss of
130+ // / precision.
130131 Result<double > to_double () const noexcept {
131132 return std::visit (
132133 [](auto _v) -> Result<double > {
133134 using V = std::remove_cvref_t <decltype (_v)>;
134135 if constexpr (std::is_same_v<V, double >) {
135136 return _v;
137+ } else if constexpr (std::is_same_v<V, int64_t >) {
138+ auto _d = static_cast <double >(_v);
139+ if (static_cast <int64_t >(_d) == _v) {
140+ return _d;
141+ } else {
142+ return error (
143+ " rfl::Generic: Could not cast the underlying value to a "
144+ " double without loss of precision." );
145+ }
136146 } else {
137147 return error (
138148 " rfl::Generic: Could not cast the underlying value to a "
You can’t perform that action at this time.
0 commit comments