Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 12077)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 12078)
@@ -112,5 +112,5 @@
 
             order <<= 24;
-            order |= floatToFixed(this.style.majorZIndex, 24, 8);
+            order |= floatToFixed(this.style.majorZIndex, 24);
 
             // selected on top of member of selected on top of unselected
@@ -120,5 +120,5 @@
 
             order <<= 24;
-            order |= floatToFixed(this.style.zIndex, 24, 8);
+            order |= floatToFixed(this.style.zIndex, 24);
 
             order <<= 1;
@@ -132,20 +132,27 @@
 
         /**
-         * Converts a float to a fixed pointdecimal so that the order stays the same.
+         * Converts a float to a fixed point decimal so that the order stays the same.
          *
          * @param number The float to convert
          * @param totalBits
-         *            Total number of bits. 1 sign bit, then the bits before the
-         *            decimal point, then those after.
-         * @param afterDecimalBits
-         *            Number of fixed bits after the decimal point.
+         *            Total number of bits. 1 sign bit. There should be at least 15 bits.
          * @return The float converted to an integer.
          */
-        private static long floatToFixed(double number, int totalBits, int afterDecimalBits) {
-            long value = (long) (number * (1L << afterDecimalBits));
-            long highestBitMask = 1L << totalBits - 1;
-            long valueMask = highestBitMask - 1;
-            long signBit = number < 0 ? 0 : highestBitMask;
-            return signBit | value & valueMask;
+        protected static long floatToFixed(float number, int totalBits) {
+            long value = Float.floatToIntBits(number) & 0xffffffffL;
+
+            boolean negative = (value & 0x80000000L) != 0;
+            // Invert the sign bit, so that negative numbers are lower
+            value ^= 0x80000000L;
+            // Now do the shift. Do it before accounting for negative numbers (symetry)
+            if (totalBits < 32) {
+                value >>= (32 - totalBits);
+            }
+            // positive numbers are sorted now. Negative ones the wrong way.
+            if (negative) {
+                // Negative number: re-map it
+                value = (1L << (totalBits - 1)) - value;
+            }
+            return value;
         }
 
Index: /trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererTest.java	(revision 12078)
+++ /trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererTest.java	(revision 12078)
@@ -0,0 +1,79 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.osm.visitor.paint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer.StyleRecord;
+
+/**
+ * Test the {@link StyledMapRenderer}
+ * @author Michael Zangl
+ * @since 12078
+ */
+public class StyledMapRendererTest {
+
+    /**
+     * Tests the floatToFixed function.
+     */
+    @Test
+    public void testFloatToFixed() {
+        long inf = floatToFixedCheckBits(Float.POSITIVE_INFINITY, 24);
+        long big = floatToFixedCheckBits(Float.MAX_VALUE, 24);
+        long two = floatToFixedCheckBits(2, 24);
+        // We use 15 bit for the significand. This should give us at least 3 decimal places
+        long x = floatToFixedCheckBits(1.001f, 24);
+        long one = floatToFixedCheckBits(1, 24);
+        long delta = floatToFixedCheckBits(Float.MIN_VALUE * 500, 24);
+        long epsilon = floatToFixedCheckBits(Float.MIN_VALUE, 24);
+        long zero = floatToFixedCheckBits(0, 24);
+        long negzero = floatToFixedCheckBits(-0, 24);
+        long negepsilon = floatToFixedCheckBits(-Float.MIN_VALUE, 24);
+        long negdelta = floatToFixedCheckBits(-Float.MIN_VALUE * 500, 24);
+        long negone = floatToFixedCheckBits(-1, 24);
+        long negx = floatToFixedCheckBits(-1.001f, 24);
+        long negtwo = floatToFixedCheckBits(-2, 24);
+        long negbig = floatToFixedCheckBits(-Float.MAX_VALUE, 24);
+        long neginf = floatToFixedCheckBits(Float.NEGATIVE_INFINITY, 24);
+
+        System.out.println(Integer.toHexString(Float.floatToIntBits(-Float.MAX_VALUE)));
+        // Positive
+        assertTrue(inf > big);
+        assertTrue(big > two);
+        assertTrue(two > x);
+        assertTrue(x > one);
+        assertTrue(one > delta);
+
+        // Close to zero - we don't care which way the epsilon round, but delta should not equal zero.
+        assertTrue(delta > zero);
+        assertTrue(negzero > negdelta);
+
+        assertTrue(delta >= epsilon);
+        assertTrue(epsilon >= zero);
+        assertTrue(zero >= negzero);
+        assertTrue(negzero >= negepsilon);
+        assertTrue(negepsilon >= negdelta);
+
+        // Negative
+        assertTrue(negdelta > negone);
+        assertTrue(negone > negx);
+        assertTrue(negx > negtwo);
+        assertTrue(negtwo > negbig);
+        assertTrue(negbig > neginf);
+
+        // Check the bit count
+        floatToFixedCheckBits((float) Math.PI, 32);
+        floatToFixedCheckBits((float) Math.PI, 20);
+        floatToFixedCheckBits((float) Math.PI, 25);
+        floatToFixedCheckBits(Float.NaN, 24);
+    }
+
+    private long floatToFixedCheckBits(float number, int totalBits) {
+        long result = StyleRecord.floatToFixed(number, totalBits);
+        long shouldBeZero = result >> totalBits;
+        assertEquals(0, shouldBeZero);
+        return result;
+    }
+
+}
