Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 2. Basic Erlang > Term Comparison

2.8. Term Comparison

Term comparisons in Erlang take two expressions on either side of the comparison operator. The result of the expression is one of the Boolean atoms true or false. The equal (==) and not equal (/=) operators compare the values on either side of the operator without paying attention to the data types. Typing 1 == one returns false, whereas one == one returns true.

Comparisons such as 1 == 1.0 will return true and 1 /= 1.0 will return false, as integers are converted to floats before being compared with them in such a comparison. You get around this by using the operators exactly equal to and not exactly equal to, as these operators compare not only the values on either side of the equation, but also their data types. So, for example, 1 =:= 1.0 and 1 =/= 1 will both return false, and 1 =/= 1.0 returns true.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial