MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / toBool

Function toBool

src/sys/expressionparser.cxx:189–195  ·  view source on GitHub ↗

Convert a real value to a Boolean Throw exception if `rval` isn't close to 0 or 1

Source from the content-addressed store, hash-verified

187/// Convert a real value to a Boolean
188/// Throw exception if `rval` isn't close to 0 or 1
189bool 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
197BoutReal FieldBinary::generate(const Context& ctx) {
198 BoutReal lval = lhs->generate(ctx);

Callers 2

generateMethod · 0.85
generateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected