Convert a real value to a Boolean Throw exception if `rval` isn't close to 0 or 1
| 187 | /// Convert a real value to a Boolean |
| 188 | /// Throw exception if `rval` isn't close to 0 or 1 |
| 189 | bool toBool(BoutReal rval) { |
| 190 | int ival = ROUND(rval); |
| 191 | if ((fabs(rval - static_cast<BoutReal>(ival)) > 1e-3) or (ival < 0) or (ival > 1)) { |
| 192 | throw BoutException(_("Boolean operator argument {:e} is not a bool"), rval); |
| 193 | } |
| 194 | return ival == 1; |
| 195 | } |
| 196 | |
| 197 | BoutReal FieldBinary::generate(const Context& ctx) { |
| 198 | BoutReal lval = lhs->generate(ctx); |