float(?term) [ISO]

This arithmetic predicate converts it's argument to a floating point number.

If this clause is not used in arithmetic expressions then it succeeds if it's argument is a floating point value, else not. Below there are several examples using the clause for type testing and in arithmetic expressions.

see also: atom/1 atomic/1 compound/1 integer/1 instance/1 nonvar/1 number/1 var/1 Prolog arithmetic

Type testing examples
float("hello"). fails
float(-10.1) succeeds
float(9). fails
float([a]). fails
X=12.3, float(X) succeeds

 

Arithmetic examples
X is float(1). X = 1
X is float(3) / 2 X = 1.5

 

 

info@trinc-prolog.com