函数remquo做了什么以及它可以用于什么?

前端之家收集整理的这篇文章主要介绍了函数remquo做了什么以及它可以用于什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
通过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 the remainder functions. In
the object pointed to by quo they store a value whose sign is the sign of x/y and whose
magnitude is congruent modulo 2^n
to the magnitude of the integral quotient of x/y,where
n is an implementation-defined integer greater than or equal to 3.

The remquo functions return x REM y. If y is zero,the value stored in the object
pointed to by quo 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作为输出参数返回.它优于上述语法的优点是它只进行一次除法运算.

原文链接:https://www.f2er.com/c/112749.html

猜你在找的C&C++相关文章