remquo结果没了感觉 [英] remquo Results Not Making Sense

查看:248
本文介绍了remquo结果没了感觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了这里 remquo 应返回:

如果成功,则返回该部门的浮点余X / Y 中的std ::其余定义,和值,其标志是标志 X / Y ,其幅度是一致的模2 N
   到 X / Y 的积分商的规模,其中的 N 的是一个实现定义的整数大于或等于的 3

If successful, returns the floating-point remainder of the division x/y as defined in std::remainder, and a value whose sign is the sign of x/y and whose magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where n is an implementation-defined integer greater than or equal to 3.

现在显然我误解了所有的技术语汇说,因为我以为我会找回划分的分数结果。相反,这种操作:

Now clearly I've misunderstood all that techno-speak cause I thought that I was going to get back the fractional result of the division. Instead this operation:

int quot;
const float rem = remquo(7.0F, 4.0F, &quot);

设定 QUOT 来的 2 REM 来的 -1.0 !我可以看到这是有效的,因为的 4.0 * 2 = 8.0 的和的 7.0 - 8.0 = -1.0 的。但是我们为什么要使用 QUOT ,这将导致负 REM ?我不应该被取回一个 QUOT 中的 1 的和 REM 3.0 的?

Sets quot to 2 and rem to -1.0! I can see how that is valid because 4.0 * 2 = 8.0 and 7.0 - 8.0 = -1.0. But why are we using a quot that will result in a negative rem? Shouldn't I be getting back a quot of 1 and a rem of 3.0?

推荐答案

由于您的问题是关于通过 remquo 返回的值,它完全是关于的std ::其余,因为 remquo 的行为一部分直接定义为等同于 STD: :余

Since your question is about the value returned by remquo, it is entirely about std::remainder, since that part of remquo's behavior is defined directly as identical to that of std::remainder.

的std ::其余提供了IEEE 754余操作,这是从 FMOD 不同 FMOD 可以预期总是积极的,而IEEE 754余相对于定义的积分商数最近整数数学商X / Y,使余数=说明X - Y * q 产生负结果每次的数学时间商发的最高为下一个整数。

std::remainder provides the IEEE 754 remainder operation, which is different from fmod in that the fmod of two positive values can be expected to be always positive, whereas the IEEE 754 remainder is defined with respect to the integral quotient q as the nearest integer to the mathematical quotient x/y, so that remainder = x - y*q produces a negative result each time the mathematical quotient rounds up to the next integer.

在IEEE 754余操作是一个被在<一个讨论href=\"http://stackoverflow.com/questions/158120/math-ieeeremainder-returns-negative-results-why\">question Math.IEEERemainder返回负的成绩。,所以你可能要阅读并接受的答案,尽管他们对不同的编程语言。

The IEEE 754 remainder operation is the one being discussed in the question "Math.IEEERemainder returns negative results." so you might want to read it and the accepted answer although they are about a different programming language.

注:关于商作为规范的一部分,模2同余 N 的积分商的规模只是意味着你没有得到整个积分商,这的确可能不适合的 INT 键入(想想 remquo的(FLT_MAX,1.0F,...),相反,你会得到一个实现定义数目的积分商数的至少显著位。位的实现定义数目只有变必须是至少三个,但也可以是其他。

Note: the part of the specification about the quotient being "congruent modulo 2n to the magnitude of the integral quotient" simply means that you do not get the entire integral quotient, which indeed might not fit an int type (think of remquo(FLT_MAX, 1.0f, ...). Instead, you get an implementation-defined number of the least significant bits of the integral quotient. The implementation-defined number of bits that you get must be at least three, but can be more.

这篇关于remquo结果没了感觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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