这个功能是什么以及它可以用来做什么? [英] What does the function remquo do and what can it be used for?

查看:84
本文介绍了这个功能是什么以及它可以用来做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过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);




remquo 函数计算与 余数 函数相同的余数。在
中,指向quo的对象存储一个值,其符号是 x / y 的符号,其
幅度是对于 x / y 的积分商数的模一致模2 ^ n
,其中
n 是一个实现定义的大于或等于3的整数。
$ b

remquo 函数返回 x REM y 即可。如果 y 为零,则存储在 quo 指向的对象
中的值code> 是未指定的,并且是否发生域错误或函数
返回零是实现定义的。

我知道它返回的是什么,它返回 fmod(x,y),但我不明白整个 quo 部分。它在语义上等于这个吗?

  * quo =(int)x / y; 
* quo%= n; / * n实现定义* /

我的最后一个问题是,这个函数有什么用处? / p>

解决方案

编辑:正如Jeffrey Scofield所说他的答案,返回的商并不是 x / y ,但是低3位(加号)

它相当于(最大类型差异):

  quo = x / y; 
rem = x%y;

其中 rem 是返回值,并且 quo 作为输出参数返回。

与上述语法相比,它的优势在于它只执行一次除法操作。


Reading through the C specs I found this function:

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.

I understand what it returns, it returns fmod(x, y), but I don't understand the whole quo part. Is it semantically equal to this?

*quo = (int) x/y;
*quo %= n; /* n implementation defined */

And my last question, for what could this function be useful?

解决方案

EDIT: As Jeffrey Scofield said in his answer, the returned quotient really isn't x/y, but the low 3 bits (plus sign) of the quotient.

It's equivalent to (up to type differences):

quo = x/y;
rem = x%y;

Where rem is the return value, and quo is returned as an output parameter.
Its advantage over the above syntax is that it does just one division operation.

这篇关于这个功能是什么以及它可以用来做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆