コード例 #1
0
ファイル: XxDataReader.cs プロジェクト: denghe/xxlib_codegens
        public void Read(ref float v)
        {
            var fu = new FloatingInteger {
                b0 = buf[offset + 0],
                b1 = buf[offset + 1],
                b2 = buf[offset + 2],
                b3 = buf[offset + 3]
            };

            v       = fu.f;
            offset += 4;
        }
コード例 #2
0
        public void WriteDirect(float v)
        {
            var fu = new FloatingInteger {
                f = v
            };

            buf[len + 0] = fu.b0;
            buf[len + 1] = fu.b1;
            buf[len + 2] = fu.b2;
            buf[len + 3] = fu.b3;
            len         += 4;
        }
コード例 #3
0
 public void WriteDirect(double v)
 {
     if (v == 0)
     {
         buf[len++] = 0;
     }
     else
     {
         if (double.IsNaN(v))
         {
             buf[len++] = 1;
         }
         else if (double.IsNegativeInfinity(v))
         {
             buf[len++] = 2;
         }
         else if (double.IsPositiveInfinity(v))
         {
             buf[len++] = 3;
         }
         else
         {
             int intv = (int)v;
             if (v == (double)intv)
             {
                 buf[len++] = 4;
                 Bit7Write(buf, ref data.len, ZigZagEncode(intv));    // Write(intv);
             }
             else
             {
                 buf[len++] = 5;
                 var du = new FloatingInteger {
                     d = v
                 };
                 buf[len + 0] = du.b0;
                 buf[len + 1] = du.b1;
                 buf[len + 2] = du.b2;
                 buf[len + 3] = du.b3;
                 buf[len + 4] = du.b4;
                 buf[len + 5] = du.b5;
                 buf[len + 6] = du.b6;
                 buf[len + 7] = du.b7;
                 len         += 8;
             }
         }
     }
 }
コード例 #4
0
ファイル: XxBBuffer.cs プロジェクト: denghe/xxlib_csharp
        public void Read(ref double v)
        {
            switch (buf[offset++])
            {
            case 0:
                v = 0;
                break;

            case 1:
                v = double.NaN;
                break;

            case 2:
                v = double.NegativeInfinity;
                break;

            case 3:
                v = double.PositiveInfinity;
                break;

            case 4:
                uint tmp = 0;
                Bit7Read(ref tmp, buf, ref offset, dataLen);
                v = ZigZagDecode(tmp);
                break;

            case 5:
                var du = new FloatingInteger
                {
                    b0 = buf[offset + 0],
                    b1 = buf[offset + 1],
                    b2 = buf[offset + 2],
                    b3 = buf[offset + 3],
                    b4 = buf[offset + 4],
                    b5 = buf[offset + 5],
                    b6 = buf[offset + 6],
                    b7 = buf[offset + 7]
                };
                v       = du.d;
                offset += 8;
                break;

            default:
                throw new NotSupportedException();
            }
        }