[erlang-questions] Mystery float binary matching
Konstantin Tcepliaev
f355@REDACTED
Wed Jun 27 21:01:05 CEST 2012
Hello Michael,
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.
Regards,
--
Konstantin
27.06.2012, 22:15, "Michael Uvarov" <freeakk@REDACTED>:
> Hi,
>
> 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>>.
> <<0,0,0,0,0,0,0,0>>
>
> --
> Best regards,
> Uvarov Michael
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list