Floating point issue with NaN values
See original GitHub issueHi, there. Thanks for providing this nice library!
I found myself in a problem here that is related to the following lines:
from strictyaml import Map, Float, load
schema = Map(
{
"number_one": Float(),
"not_a_number": Float(),
}
)
yaml_string = (
"number_one: 1.0\n"
"not_a_number: .nan"
)
load(yaml_string=yaml_string, schema=schema)
and I got this:
strictyaml.exceptions.YAMLValidationError: when expecting a float
found arbitrary text
in "<unicode string>", line 2, column 1:
not_a_number: '.nan'
^ (line: 2)
According to https://yaml.org/spec/1.2/spec.html#id2804092, .nan
, .inf
or -.inf
are part of the canonical form of the floating point representation.
(In fact, I would like to do that using dirty_load
, as I need a readable representation for my matrices (I’m using Seq(Seq(Float))
), but that’s another story, as dirty_load
seems to be just another way of calling generic_load
with allow_flow_style
.)
Am I missing something here or is there a workaround for it?
Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (15 by maintainers)
Top Results From Across the Web
NaN - Wikipedia
In computing, NaN standing for Not a Number, is a member of a numeric data type that can be interpreted as a value...
Read more >Why does IEEE 754 reserve so many NaN values?
It seems that the IEEE 754 standard defines 16,777,214 32-bit floating point values as NaNs, or 0.4% of all possible values.
Read more >If it's not a number, what is it? Demystifying NaN ... - Lucidchart
The problem is that floating-point numbers look and act almost like the numbers we all learned about in school. The word “almost“ hides...
Read more >IEEE Floating-point overview - IBM
If the data or program code contains signaling NaN values (NAN), include nans among the -qfloat suboptions. (A signaling NaN is different from...
Read more >Infinity and NaN (The GNU C Library)
An expression representing a value which is “not a number”. This macro is a GNU extension, available only on machines that support the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would say accept only
INF
andNaN
(think this form is least likely to be mistaken for a standard string). StrictYAML aims to be fully roundtripable, which means there should only be one valid representation. It is a restricted subset of YAML, so no need to support every variation. You could check for other variations and print an error saying to useINF
orNaN
.Yes, please do. I’ll merge and release a new version on pypi once you’re done.
Thank you for doing this.