From b074099cc6bdb81285a17e0248373f199c695719 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 5 Sep 2012 20:43:03 +0200 Subject: Add new binary conversion bifs Added: binary_to_integer/1,2, integer_to_binary/1,2 --- erts/doc/src/erlang.xml | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'erts/doc') diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index 5a63aaadc6..36d606130f 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -299,6 +299,32 @@

Failure: badarg if the atom does not already exist.

+ + + Convert from text representation to an integer + +

Returns an integer whose text representation is + Binary.

+
+> binary_to_integer(<<"123">>).
+123
+

Failure: badarg if Binary contains a bad + representation of an integer.

+
+
+ + + Convert from text representation to an integer + +

Returns an integer whose text representation in base + Base is Binary.

+
+> binary_to_integer(<<"3FF">>, 16).
+1023
+

Failure: badarg if Binary contains a bad + representation of an integer.

+
+
Convert a binary to a list @@ -1429,7 +1455,28 @@ os_prompt% {one,new,two,three} - + + + Text representation of an integer + +

Returns a binary which corresponds to the text + representation of Integer.

+
+> integer_to_binary(77).
+<<"77">>
+
+
+ + + Text representation of an integer + +

Returns a binary which corresponds to the text + representation of Integer in base Base.

+
+> integer_to_binary(1023, 16).
+<<"3FF">>
+
+
Text representation of an integer -- cgit v1.2.3 From 5279b3af4efee5d3e7d9755f0f06bd7b0f5dd05c Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 8 Feb 2013 18:23:22 +0100 Subject: Add float_to_binary and binary_to_float --- erts/doc/src/erlang.xml | 53 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'erts/doc') diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml index 36d606130f..06fefa8efb 100644 --- a/erts/doc/src/erlang.xml +++ b/erts/doc/src/erlang.xml @@ -299,6 +299,18 @@

Failure: badarg if the atom does not already exist.

+ + + Convert from text representation to a float + +

Returns the float whose text representation is Binary.

+
+> binary_to_float(<<"2.2017764e+0">>).
+2.2017764
+

Failure: badarg if Binary contains a bad + representation of a float.

+
+
Convert from text representation to an integer @@ -987,26 +999,38 @@ true - + Text representation of a float -

Returns a string which corresponds to the text - representation of Float.

+

The same as float_to_binary(Float,[{scientific,20}]).

+
+
+ + + Text representation of a float formatted using given options + +

Returns a binary which corresponds to the text + representation of Float using fixed decimal + point formatting. The Options behave in the same + way as float_to_list/2. +

-> float_to_list(7.0).
-"7.00000000000000000000e+00"
+> float_to_binary(7.12, [{decimals, 4}]). +<<"7.1200">> +> float_to_binary(7.12, [{decimals, 4}, compact]). +<<"7.12">> +
+
+ + + Text representation of a float + +

The same as float_to_list(Float,[{scientific,20}]).

- float_to_list(Float, Options) -> string() + Text representation of a float formatted using given options - - Float = float() - Options = [Option] - Option = {decimals, Decimals::0..253} | - {scientific, Decimals::0..249} | - compact -

Returns a string which corresponds to the text representation of Float using fixed decimal point formatting. @@ -1019,7 +1043,8 @@ true only meaningful together with the decimals option). When scientific option is provided, the float will be formatted using scientific notation with Decimals digits of precision. If - Options is [] the function behaves like float_to_list/1. + Options is [] the function behaves like + float_to_list/1.

 > float_to_list(7.12, [{decimals, 4}]).
-- 
cgit v1.2.3