|
Re: REMAINDER function return negative value [message #167255 is a reply to message #167251] |
Wed, 12 April 2006 02:39   |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
From the manual | Purpose
REMAINDER returns the remainder of m divided by n.
This function takes as arguments any numeric datatype or any nonnumeric datatype that can be implicitly converted to a numeric datatype. Oracle determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype.
The MOD function is similar to REMAINDER except that it uses FLOOR in its formula, whereas REMAINDER uses ROUND. Please refer to MOD .
See Also:
Table 2-11, "Implicit Type Conversion Matrix" for more information on implicit conversion and "Numeric Precedence " for information on numeric precedence
If n = 0 or m = infinity, then Oracle returns
An error if the arguments are of type NUMBER
NaN if the arguments are BINARY_FLOAT or BINARY_DOUBLE.
If n != 0, then the remainder is m - (n*N) where N is the integer nearest m/n.
If m is a floating-point number, and if the remainder is 0, then the sign of the remainder is the sign of m. Remainders of 0 are unsigned for NUMBER values.
|
Note the bolded section:
REMAINDER(3, 2) => m=3, n=2
If n != 0 (it is!) then remainder = m - (n*N) where N is the integer nearest m/n.
m/n = 1.5, the nearest integer to 1.5 is 2, so:
remainder = 3 - (2*2) = -1
Non-intuitive, but exactly as documented.
Use MOD(3,2) if you dont like it.
Ross Leishman
|
|
|
|