32 位 ieee754 浮点编码为何使用 127 作为阶码偏移量? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hazard
V2EX    问与答

32 位 ieee754 浮点编码为何使用 127 作为阶码偏移量?

  •  
  •   hazard 2014-08-14 21:55:31 +08:00 5902 次点击
    这是一个创建于 4079 天前的主题,其中的信息可能已经有所发展或是发生改变。
    仅仅是强行规定吗?
    8 条回复    2014-08-15 11:39:40 +08:00
    starfish
        1
    starfish  
       2014-08-15 00:57:12 +08:00
    本来想直接给你解释,但写了一大堆东西后发现解释起来比较麻烦,所以请自行参考下列网页:

    http://en.wikipedia.org/wiki/Binary32

    http://babbage.cs.qc.cuny.edu/IEEE-754.old/References.xhtml
    bcxx
        2
    bcxx  
       2014-08-15 01:02:45 +08:00
    额你 e 是 8 位那肯定是 127 啊……(为啥是 127 这个就要解释移码这玩意的作用了
    hazard
        3
    hazard  
    OP
       2014-08-15 01:21:44 +08:00
    @bcxx 一般的移码偏移不都是128么?
    hazard
        4
    hazard  
    OP
       2014-08-15 01:25:56 +08:00
    @starfish 能把那一堆东西发出来么。。。。?
    bcxx
        5
    bcxx  
       2014-08-15 09:40:17 +08:00
    @hazard 是 2^(n - 1) - 1 啦 http://en.wikipedia.org/wiki/Exponent_bias

    > By arranging the fields so that the sign bit is in the most significant bit position, the biased exponent in the middle, then the mantissa in the least significant bits, the resulting value will be ordered properly, whether it's interpreted as a floating point or integer value. This allows high speed comparisons of floating point numbers using fixed point hardware.

    大概用这句就能解释了吧?
    hazard
        6
    hazard  
    OP
       2014-08-15 09:45:46 +08:00
    @bcxx 你认为是保持符号位?进行快速比较?
    但比如阶码真值为0000 0000 加了127后是 0111 1111
    而若阶码真值为 0000 0001 加了127 之后是 1000 0000
    还是要要减了127后才能比较大小啊。。。否则一个负数怎么会比一个正数大呢?
    bcxx
        7
    bcxx  
       2014-08-15 09:49:43 +08:00
    @hazard 你去画一下数轴看看加了 bias 之后的变化就应该明白了(噢加了 bias 之后最高位是 1 的就都是负数了)
    hazard
        8
    hazard  
    OP
       2014-08-15 11:39:40 +08:00
    @bcxx 1 加了Bias以后是 128 最高位是1 但它本身不是负数啊。。。?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2959 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 13:04 PVG 21:04 LAX 06:04 JFK 09:04
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86