本文介绍了加倍除以浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我相信这将一个int转换成浮点值拆分成价值的符号指数和部分组件的功能。利用IEEE 754重新present浮点值。

 符号试验(无符号X){
    //拆分符号指数和部分的给定的位,结合以返回    无符号整数符号=(X安培;为0x80000000)GT;> 31;
    unsigned int类型博览会=(X安培; 0x7F800000)GT;> 23;
    unsigned int类型压裂=(X安培; 0x007fffff);    返回(符号<< 31)| (世博<< 23)|压裂;
}

我不确定但我怎么可能从这个浮点重新presentation计算一半或一倍值。

 符号一倍(无符号X){
    //获取浮动
    //浮= unsigned int类型浮动
    // doubleFloat = 2 *˚F
    //如果浮动不是一个数字
        //返回无符号的浮动
    //否则返回半浮球无符号整数    无符号整数符号=(X安培;为0x80000000)GT;> 31;
    unsigned int类型博览会=(X安培; 0x7F800000)GT;> 23;
    unsigned int类型压裂=(X安培; 0x007fffff);    如果(世博==为0xFF)
        返回UF;
    否则...
}


解决方案

看来你使用的是IEEE 754重新present浮点值。

如果您要仔细二进制重新presentation,你只需要通过1 expoent递增。如果你想要半也是如此,只是减1

请记住,这是真的只有当您的号码是在正常范围内,甚至包括加倍或减半后

I have the function which I believe will convert an int into a floating point value split into the sign exponent and fraction components of the value. Using IEEE 754 to represent Float values.

unsigned test(unsigned x) {
    // split the given bits of sign exponent and fraction, combine to return

    unsigned int sign = (x & 0x80000000) >> 31;
    unsigned int expo = (x & 0x7F800000) >> 23;
    unsigned int frac = (x & 0x007fffff);

    return (sign << 31) | (expo << 23) | frac;
}

I'm unsure however how I could compute the halved or doubled values from this floating point representation.

unsigned doubled(unsigned x) {
    // get float
    // float = unsigned int to float
    // doubleFloat  = 2*f
    // if float is not a number
        // return unsigned float
    // else return unsigned integer of half float

    unsigned int sign = (x & 0x80000000) >> 31;
    unsigned int expo = (x & 0x7F800000) >> 23;
    unsigned int frac = (x & 0x007fffff);

    if (expo == 0xff)
        return uf;
    else ...
}
解决方案

It seems that you are using IEEE 754 to represent Float values.

If you want to double the binary representation, you just need to increment by 1 the expoent. The same is true if you want to half, just decrement by 1

Remember that this is true only if your number is in normal range, including even after doubling or halving

这篇关于加倍除以浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:34