__ddiv_ru的语义 [英] Semantics of __ddiv_ru

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

问题描述

来自

From the documentation of __ddiv_ru I expect that the following code result is ceil(8/32) = 1.0, instead I obtain 0.25.

#include <iostream>

using namespace std;

__managed__ double x;
__managed__ double y;
__managed__ double r;

__global__ void ceilDiv()
{
    r = __ddiv_ru(x,y);
}

int  main()
{
    x = 8;
    y = 32;
    r = -1;

    ceilDiv<<<1,1>>>();
    cudaDeviceSynchronize();

    cout << "The ceil of " << x << "/" << y << " is " << r << endl;

    return 1;
}

我错过了什么?

推荐答案

您得到的结果是正确的。

The result you are obtaining is correct.

您使用的内在函数对双精度除法使用特定的IEEE 754-2008舍入模式对单元的有效位的最后一位(ULP)进行舍入。这可以控制在无法以所选格式准确表示结果时发生的情况。在这种情况下,您选择了舍入,这意味着除法结果中产生的有效位数的最后一位被舍入(向+∞)。在您的情况下,所有舍入模式都应产生相同的结果,因为该结果可以用IEEE 754 binary64格式精确表示(舍入为2的幂)。

The intrinsic you are using implements double precision division with a specific IEEE 754-2008 rounding mode for the unit in the last place (ULP) of the significand. This controls what happens when a result cannot be exactly represented in the selected format. In this case you have selected round up, which means the last digit of the significand produced in the division result is rounded up (toward +∞). In your case all rounding modes should produce the same result because the result can be exactly represented in IEEE 754 binary64 format (it is a round power of 2).

请阅读

这篇关于__ddiv_ru的语义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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