[erlang-questions] Mystery float binary matching
Wed Jun 27 21:01:05 CEST 2012
There's no mystery here. The double-precision float you're trying to match represents -Infinity according to IEEE-754, which has no equivalent in Erlang and is usually represented by atom 'infinity', which is another datatype.
More examples that don't match:
<<0,0,0,0,0,0,240,127>> - +Infinity
<<1,0,0,0,0,0,240,127>> - NaN
I'm not sure what you should do if you need to parse the input which may contain those special values. The best I can think of is to match the field in question as an eight bytes binary, then check that binary for specials, and only then match it to float.
Also, beware of endianness.
27.06.2012, 22:15, "Michael Uvarov" <>:
> What is the problem with this code?
> 1> <<_/native-float>> = <<0,0,0,0,0,0,240,255>>.
> ** exception error: no match of right hand side value <<0,0,0,0,0,0,240,255>>
> 2> <<_/native-float>> = <<0,0,0,0,0,0,0,0>>.
> Best regards,
> Uvarov Michael
> erlang-questions mailing list
More information about the erlang-questions