通过C规范阅读我发现了这个功能:
double remquo(double x,double y,int *quo); float remquof(float x,float y,int *quo); long double remquol(long double x,long double y,int *quo);
The
remquo
functions compute the same remainder as theremainder
functions. In
the object pointed to by quo they store a value whose sign is the sign ofx/y
and whose
magnitude is congruent modulo 2^n
to the magnitude of the integral quotient ofx/y
,where
n is an implementation-defined integer greater than or equal to 3.The
remquo
functions returnx
REMy
. Ify
is zero,the value stored in the object
pointed to byquo
is unspecified and whether a domain error occurs or the functions
return zero is implementation defined.
我理解它返回的内容,它返回fmod(x,y),但我不理解整个部分.它在语义上是否与此相同?
*quo = (int) x/y; *quo %= n; /* n implementation defined */
我的最后一个问题是,这个功能有用吗?
解决方法
编辑:正如杰弗里斯科菲尔德在
his answer所说,返回的商实际上不是x / y,而是商的低3位(加号).
它相当于(最多类型差异):
quo = x/y; rem = x%y;
其中rem是返回值,quo作为输出参数返回.它优于上述语法的优点是它只进行一次除法运算.