Просмотр исходного кода

Fallback for Erlang < R16B.

Thanks @connorsml.
Andreas Stenius 11 лет назад
Родитель
Сommit
0c67090a54
1 измененных файлов с 10 добавлено и 4 удалено
  1. 10 4
      src/erlydtl_filters.erl

+ 10 - 4
src/erlydtl_filters.erl

@@ -720,10 +720,16 @@ cast_to_float(Input) when is_float(Input) ->
 cast_to_float(Input) when is_integer(Input) ->
     Input + 0.0;
 cast_to_float(Input) when is_binary(Input) ->
-    try binary_to_float(Input)
-    catch
-        error:_Reason ->
-            binary_to_integer(Input) + 0.0
+    %% be compatible with releases prior to R16B
+    case erlang:function_exported(erlang, binary_to_float, 1) of
+        true ->
+            try binary_to_float(Input)
+            catch
+                error:_Reason ->
+                    binary_to_integer(Input) + 0.0
+            end;
+        false ->
+            cast_to_float(binary_to_list(Input))
     end;
 cast_to_float(Input) when is_list(Input) ->
     try list_to_float(Input)