Implementing single-precision division as double-precision multiplication

后端 未结 3 1008
礼貌的吻别
礼貌的吻别 2020-12-19 20:29

Question

For a C99 compiler implementing exact IEEE 754 arithmetic, do values of f, divisor of type float exist such that

3条回答
  •  隐瞒了意图╮
    2020-12-19 21:09

    Random search resulted in an example.

    Looks like when the result is a "denormal/subnormal" number, the inequality is possible. But then, maybe my platform is not IEEE 754 compliant?

    f        0x1.7cbff8p-25 
    divisor -0x1.839p+116
    q       -0x1.f8p-142
    q2      -0x1.f6p-142
    
    int MyIsFinite(float f) {
      union {
        float f;
        unsigned char uc[sizeof (float)];
        unsigned long ul;
      } x;
      x.f = f;
      return (x.ul & 0x7F800000L) != 0x7F800000L;
    }
    
    float floatRandom() {
      union {
        float f;
        unsigned char uc[sizeof (float)];
      } x;
      do {
        size_t i;
        for (i=0; i

    Eclipse PC Version: Juno Service Release 2 Build id: 20130225-0426

提交回复
热议问题