Function to_float fails to parse "0": Invalid float "0": not a normal f64 number
Closed this issue ยท 2 comments
PetrHeinz commented
A note for the community
- Please vote on this issue by adding a ๐ reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Problem
When using to_float
on a zero (either "0", "0.0", "0.000", ...), parsing fails with:
error[E000]: function call error for "to_float" at (142:156): NaN number not supported "Invalid float \"0\": not a normal f64 number"
โโ :4:8
โ
4 โ test = to_float!("0")
โ ^^^^^^^^^^^^^^ NaN number not supported "Invalid float \"0\": not a normal f64 number"
โ
= see language documentation at https://vrl.dev
= try your code in the VRL REPL, learn more at https://vrl.dev/examples
This issue was introduced in newly released 0.43.0.
Configuration
No response
Version
vector 0.43.0 (aarch64-apple-darwin 88e017f 2024-12-03 22:44:54.502541095)
Debug Output
No response
Example Data
"one": "1",
"zero": "0",
"nan": "nan"
}
.zero_float, .zero_float_err = to_float(.zero)
.one_float, .one_float_err = to_float(.one)
.nan_float, .nan_float_err = to_float(.nan)
{
"nan": "nan",
"nan_float": 0,
"nan_float_err": "function call error for \"to_float\" at (120:134): NaN number not supported \"Invalid float \\\"nan\\\": not a normal f64 number\"",
"one": "1",
"one_float": 1,
"one_float_err": null,
"zero": "0",
"zero_float": 0,
"zero_float_err": "function call error for \"to_float\" at (31:46): NaN number not supported \"Invalid float \\\"0\\\": not a normal f64 number\""
}
Additional Context
References
pront commented
Thanks for the report @PetrHeinz.
As an immediate workaround you can use parse_float
, see example.
We will discuss internally about the proper fix, probably checking for is_normal here is too restrictive.
pront commented
Fixed in https://crates.io/crates/vrl/0.20.1