summaryrefslogtreecommitdiff
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@dashbit.co>2020-11-28 09:17:48 +0100
committerJosé Valim <jose.valim@dashbit.co>2021-02-03 12:51:58 +0100
commitdb21c04b2570dc2a8126bb599c7de0266214e15c (patch)
treef93e2f930f5266f9eac3fcb452b88217a56c3d81 /lib/stdlib/src
parente1abadc7e86b7c80a961334bb66c38810e803e05 (diff)
downloaderlang-db21c04b2570dc2a8126bb599c7de0266214e15c.tar.gz
Support IEEE 754-2008 16-bit floats in bitstrings
This format is often used with computer graphics and AI, also in cases where data is large enough that the decreased bandwidth and storage compensates the loss of precision. The _Float16 data type is defined in the C11 extension ISO/IEC TS 18661-3:2015. Recent compilers and platforms provide support for it and recent CPUs provide specific instruction sets for them too. In some, _Float16 is storage only, which is enough for our use cases. If _Float16 is not available, functions for conversion from float to half-floats are used, ported from https://github.com/Maratyszcza/FP16.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/erl_lint.erl3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index d54f71be59..571c7951fc 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -1993,7 +1993,7 @@ bit_type(Anno, Size0, Type, St) ->
%% bit_size_check(Anno, Size, BitType, State) -> {BitSize,State}.
%% Do some checking & warnings on types
-%% float == 32 or 64
+%% float == 16 or 32 or 64
bit_size_check(_Anno, unknown, _, St) -> {unknown,St};
bit_size_check(_Anno, undefined, #bittype{type=Type}, St) ->
@@ -2009,6 +2009,7 @@ bit_size_check(Anno, Size, #bittype{type=Type,unit=Unit}, St) ->
St2 = elemtype_check(Anno, Type, Sz, St),
{Sz,St2}.
+elemtype_check(_Anno, float, 16, St) -> St;
elemtype_check(_Anno, float, 32, St) -> St;
elemtype_check(_Anno, float, 64, St) -> St;
elemtype_check(Anno, float, _Size, St) ->