1:- module(canny_maths,
2 [ frem/3,
3 fmod/3,
4
5 epsilon_equal/2,
6 epsilon_equal/3,
7
8 frexp/3,
9 ldexp/3
10 ]).
17frem(X, Y, Z) :- Z is X - round(X / Y) * Y.
24fmod(X, Y, Z) :-
25 X_ is abs(X),
26 Y_ is abs(Y),
27 frem(X_, Y_, Z_),
28 ( sign(Z_) < 0
29 -> Z0 is Z_ + Y_
30 ; Z0 = Z_
31 ),
32 Z is copysign(Z0, X).
41epsilon_equal(X, Y) :- epsilon_equal(1, X, Y). 42 43epsilon_equal(Epsilons, X, Y) :- Epsilons * epsilon >= abs(X - Y).
52frexp(X, Y, Exp) :- float_parts(X, Y, 2, Exp).
ldexp(x, exp)
function.
Uses an unusual argument order. Ordering aligns X, Y and Exp with frexp/3. Uses ** rather than ^ operator. Exp is an integer.
66ldexp(X, Y, Exp) :- Y is X * 2 ** Exp