Any reason why decimals can't be used in typespecs?

@type sample_rate :: 5.5 | 11 | 22 | 44

produces the following error:

** (CompileError) lib/flv/audio_data.ex:12: unexpected expression in typespec: 5.5

Changing it from 5.5 to 5 compiles. Any way to have a decimal as a constant in a typespec?

1 Like

Only integer literals are valid typespecs, floats are not. As far as I know, there’s no way to make it work.

That may be related to the exactness fact. 5 can be uniquely represented, while representation and value of 5.5 is fuzzy (like with all floats).

1 Like