[−][src]Function jsonlogic_rs::js_op::parse_float_add
pub fn parse_float_add(vals: &Vec<&Value>) -> Result<f64, Error>
Add values, parsing to floats first.
The JSONLogic reference implementation uses the JS parseFloat
operation
on the parameters, which behaves quite differently from the normal JS
numeric conversion with Number(val)
. While the latter uses the
toPrimitive
method on the base object Prototype, the former first
converts any incoming value to a string, and then tries to parse it
as a float. The upshot is that things that normally parse fine into
numbers in JS, like bools and null, convert to NaN, because you can't
make "false" into a number.
The JSONLogic reference implementation deals with any values that evaluate to NaN by returning null. We instead will return an error, the behavior for non-numeric inputs is not specified in the spec, and returning errors seems like a more reasonable course of action than returning null.