
![]() |
Would you like MinerWars craft mode? :) |
Blog about development of realtime graphics and game programming. If you are curious, welcome.
[StructLayout(LayoutKind.Explicit)] struct FloatIntUnion { [FieldOffset(0)] public int i; [FieldOffset(0)] public float f; } // Returns the next float after x in the direction of y. float NextAfter(float x, float y) { if (float.IsNaN(x) || float.IsNaN(y)) return x + y; if (x == y) return y; // nextafter(0, -0) = -0 FloatIntUnion u; u.i = 0; u.f = x; // shut up the compiler if (x == 0) { u.i = 1; return y > 0 ? u.f : -u.f; } if ((x > 0) == (y > x)) u.i++; else u.i--; return u.f; }