Delete  Revise 

can't do simple division with / operator

kc0olm, created Mar 24. 2017

What is the operator for simple division? 3 is 6/2. returns false, as do any such queries
Add 

Comments

Delete  Revise 

Re: can't do simple division with / operator

Jan Burse, created Mar 27. 2017

Hi,

Yes the following is correct ISO conforming behaviour:

?- 3 is 6/2.
No

The reason is simple, (/)/2 returns always a float value(*), and the present case it gives 3.0. But during term unification float values are different from integer values, here 3.

You can instead do the following and use another ISO predicate:

?- 3 =:= 6/2.
Yes

The predicate (=:=)/2, in contrast to term unification, is able to compare integers and floats, and should be used in number comparison.

Bye

(*) SWI-Prolog returns integer when it can so, but this
is not required by the ISO core standard.