FloatUnion.approxSqrt By Frank Savage (Development Manager – XNA Tools Team)
I was listening to the GDC09 talks and Mr Savage did his performance talk he mentioned a FloatUnion struct for approximate square root, but I could never find it until now…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System.Runtime.InteropServices; [StructLayout(LayoutKind.Explicit)] public struct FloatUnion { [FieldOffset(0)] public float x; [FieldOffset(0)] public int n; public float approxSqrt() { n -= 1 << 23; n = n >> 1; n += 1 << 29; return x; } } |
This was more for me, but it’s here if you ever need it
