M
M
Mat1lda2020-03-17 21:29:44
Erlang
Mat1lda, 2020-03-17 21:29:44

8 != 8.0 in Erlang - Why is that?

8.0 rem 2
Gives an error message

an error occurred when evaluating an arithmetic expression
     in operator  rem/2
        called as 8.0 rem 2

A Returns 0! Why is that? Or should I sell my soul first????
8 rem 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-03-17
@Mat1lda

rem is an integer operation.
8 is an integer (int)
8.0 is a fractional number (float).
comparison by value:
8 > 8 == 8.0.
true
12> 8 /= 8.0.
false
comparison by value and type
9> 8 =:= 8.0.
false
10 > 8 =/= 8.0.
true
I recommend always using comparison by value and type.. it's more reliable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question