V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hazard
V2EX  ›  问与答

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

  •  
  •   hazard · 2014-08-14 21:55:31 +08:00 · 5397 次点击
    这是一个创建于 3549 天前的主题,其中的信息可能已经有所发展或是发生改变。
    仅仅是强行规定吗?
    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   ·   我们的愿景   ·   实用小工具   ·   2263 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:54 · PVG 14:54 · LAX 23:54 · JFK 02:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.