我希望采用IEEE双精度并以最有效的方式删除它的任何整数部分.
我想要
1035 ->0
1045.23->0.23
253e-23=253e-23
Run Code Online (Sandbox Code Playgroud)
我不关心正确处理非正规,无穷大或NaN.我不介意有点麻烦,因为我知道我正在使用IEEE双打,所以它应该适用于各种机器.
无分支代码将是更优选的.
我的第一个念头是(伪代码)
char exp=d.exponent;
(set the last bit of the exponent to 1)
d<<=exp*(exp>0);
(& mask the last 52 bits of d)
(shift d left until the last bit of the exponent is zero, decrementing exp each time)
d.exponent=exp;
Run Code Online (Sandbox Code Playgroud)
但问题是我想不出一个有效的方法来向左移动指数的最后一位为零,如果没有设置所有最后一位,它似乎需要输出零.这似乎与基数2对数问题有关.
对此算法或任何更好的算法的帮助将非常感激.
我应该注意到我想要无分支代码的原因是因为我希望它能有效地进行矢量化.