예제 #1
0
        static float FloatSwap(float f)
        {
            var dat = new reinterpret.F2ui {
                f = f
            };

            dat.u = BinaryPrimitives.ReverseEndianness(dat.u);
            return(dat.f);
        }
예제 #2
0
        public static float InvSqrt16(float x)        // inverse square root with 16 bits precision, returns huge number when x == 0.0
        {
            Debug.Assert(initialized);
            uint a = new reinterpret.F2ui {
                f = x
            }.u;

            reinterpret.F2ui seed = new();

            double y = x * 0.5f;

            seed.u = (((3 * EXP_BIAS - 1 - ((a >> EXP_POS) & 0xFF)) >> 1) << EXP_POS) | iSqrt[(a >> (EXP_POS - LOOKUP_BITS)) & LOOKUP_MASK];
            double r = seed.f;

            r *= 1.5f - r * r * y;
            return((float)r);
        }