Emilio =?ISO-8859-1?Q?Jes=FAs?= Gallego Arias wrote: I think it's not a bug in CIAO, try: ?- Y is 1 mod 8.0. Y = 9 ? ; That is DEFINITELY a bug. There are two sensible things to do with <integer> mod <float>. (A) Complain about it, perhaps by signalling a type error exception. (B) Give the right answer.
As you can see, you're using a integer operator (mod) with real numbers. When used with integers, it gives the correct answer, but I believe mod has an undefined value when used with reals.
Not true in mathematics, and not true in IEEE arithmetic.
In mathematics, all we want is x mod y = /* Knuth's extension */ if y = 0 then x else floor(x/y) and y = 0 and floor(x/y) are perfectly well defined when x and y are any mix of integers, rationals, and floats.
The IEEE remainder() function is a little quirky; if I understand the history correctly it's meant for range reduction in trig functions.
double remainder(double x, double y)
returns r = x - ny when y is non-zero, where n is round-to-nearest-integer(x/y), the division being *exact*. If x/y is exactly half-way between two integers, the even one is chosen for n.
If x or y is NaN or |x| is Inf or y is 0, the result is NaN.
The result doesn't depend on the rounding mode in effect, because it is defined in terms of the *exact* quotient.
However, with a little glue code you get something that acts like mod does for integers. There is also the standard C function fmod().
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
Knuth's definition of x mod y is of course correct. It is
if y = 0 then x else x - y*floor(x/y).
cheers, Robert Cordery "A man's reach should exceed his grasp, or what's a metaphor?" Marshall McLuhan in Through the Vanishing Point.
"Richard A. O'Keefe" <ok(a)cs.otago.ac.nz> Sent by: owner-ciao-users(a)clip.dia.fi.upm.es 04/01/2005 08:39 AM
To ciao-users(a)clip.dia.fi.upm.es cc
Subject Re: Arithmetic Bug?
Emilio =?ISO-8859-1?Q?Jes=FAs?= Gallego Arias wrote: I think it's not a bug in CIAO, try:
?- Y is 1 mod 8.0.
Y = 9 ? ;
That is DEFINITELY a bug. There are two sensible things to do with <integer> mod <float>. (A) Complain about it, perhaps by signalling a type error exception. (B) Give the right answer.
As you can see, you're using a integer operator (mod) with real numbers. When used with integers, it gives the correct answer, but I believe mod has an undefined value when used with reals.
Not true in mathematics, and not true in IEEE arithmetic.
In mathematics, all we want is x mod y = /* Knuth's extension */ if y = 0 then x else floor(x/y) and y = 0 and floor(x/y) are perfectly well defined when x and y are any mix of integers, rationals, and floats.
The IEEE remainder() function is a little quirky; if I understand the history correctly it's meant for range reduction in trig functions.
double remainder(double x, double y)
returns r = x - ny when y is non-zero, where n is round-to-nearest-integer(x/y), the division being *exact*. If x/y is exactly half-way between two integers, the even one is chosen for n.
If x or y is NaN or |x| is Inf or y is 0, the result is NaN.
The result doesn't depend on the rounding mode in effect, because it is defined in terms of the *exact* quotient.
However, with a little glue code you get something that acts like mod does for integers. There is also the standard C function fmod().
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------