[erlang-bugs] binary pattern matching fails with 32-bit float, if decimal representation of the number cannot be converted to binary exactly

Вадзім Зенька v@REDACTED
Mon Aug 1 11:53:42 CEST 2011


WHAT:
binary pattern matching fails with 32-bit float, if decimal
representation of the number cannot be converted to binary exactly

EXAMPLE:
following code fails:

% "1.1" does not have exact binary representation
> case <<1.1:32/float>> of <<1.1:32/float>> -> ok end.
** exception error: no case clause matching <<63,140,204,205>>

> case <<63,140,204,205>> of <<1.1:32/float>> -> ok end.
** exception error: no case clause matching <<63,140,204,205>>

although

> case <<1.1:32/float>> of <<63,140,204,205>> -> ok end.
ok

% "1.5" has exact binary representation
> case <<1.5:32/float>> of <<1.5:32/float>> -> ok end.
ok

% 64-bit floats work well
> case <<1.1:64/float>> of <<1.1:64/float>> -> ok end.
ok

--
З павагай, Вадзім Зенька
v@REDACTED
vadzim@REDACTED
+375.29.407.27.17



More information about the erlang-bugs mailing list