Created
July 26, 2010 18:17
-
-
Save jfager/490965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String toLexiSortable(final double d) { | |
long tmp = Double.doubleToRawLongBits(d); | |
return toHexString('d', (tmp < 0) ? ~tmp : (tmp ^ SIGN_MASK)); | |
} | |
public static double doubleFromLexiSortable(final String s) { | |
if (!s.startsWith("d")) { | |
throw new IllegalArgumentException(s | |
+ " does not represent a double"); | |
} | |
long tmp = fromHexString(s); | |
tmp = (tmp < 0) ? (tmp ^ SIGN_MASK) : ~tmp; | |
return Double.longBitsToDouble(tmp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment