为什么在oracle中余数(25,10)为5时余数(35,10)为-5?

Why remainder(35,10) is -5 when remainder(25,10) is 5 in oracle?

我正在 运行 使用 Sql 开发人员在 oracle 11g 中进行查询。

SELECT remainder(25,10),remainder(35,10) FROM dual;

输出

REMAINDER(25,10)       REMAINDER(35,10)       
---------------------- ---------------------- 
5                      -5                     

我可以使用 MOD() 来获得想要的结果,但我的问题是为什么一个返回 +5 而另一个返回 -5?

根据documentationREMAINDER(m, n)定义为

m - (n * X) where X is the integer nearest m / n

显然,当除法结果在两个数字的中间时,Oracle 应用 "round to even":

REMAINDER(25, 10),你得到

25 / 10 = 2.5 --> nearest integer is 2 (round to even)
25 - (10 * 2) = 5

REMAINDER(35, 10),你得到

35 / 10 = 3.5 --> nearest integer is 4 (round to even)
35 - (10 * 4) = -5