English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In Erlang, number literals have2There are two types, integers and floating-point numbers. Here are some examples to illustrate how to use integers and floating-point numbers in Erlang.
Integer− The following program shows an example of using the number data type as an integer. This program shows2Addition of integers.
-module(helloworld). -export([start/0]). start() -> io:fwrite("~w",[1+1]).
The output of the above program is as follows:
2
Floating-point number − The following program shows an example of using the number data type as a floating-point number. The program shows2Addition of integers.
-module(helloworld). -export([start/0]). start() -> io:fwrite("~f~n",[1.1+1.2]), io:fwrite("~e~n",[1.1+1.2]).
The output of the above program is as follows:
2.300000 2.30000e+0
For the above program, the following key points should be noted-
When the -f option is specified, the parameter is a floating-point number, written as[-ddd.dddAmong them, precision refers to the number of decimal places. The default precision is6.
Specify the ~e option when the parameter is a floating-point number, written as[-]d.ddde+-dddwhere precision is the number of digits to be written. The default precision is6.
The following mathematical functions can be used with numbers in Erlang. Please note that all Erlang mathematical functions exist in the math library. Therefore, all the following examples will use the import statement to import all methods from the math library.
Serial Number | Mathematical Functions and Descriptions |
---|---|
1 | This method returns the sine of the specified value. |
2 | This method returns the cosine of the specified value. |
3 | This method returns the tangent of the specified value. |
4 | This method returns the arcsine of the specified value. |
5 | This method returns the arccosine of the specified value. |
6 | This method returns the arctangent of the specified value. |
7 | exp This method returns the exponent of the specified value. |
8 | This method returns the logarithm of the specified value. |
9 | This method returns the absolute value of the specified number. |
10 | This method converts the number to a floating-point value. |
11 | This method checks if the number is a floating-point value. |
12 | This method checks if the number is an integer value. |