Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: Sorting numeric strings Date: Mon, 07 May 2012 12:38:08 -0500 Organization: A noiseless patient Spider Lines: 16 Message-ID: References: <0km0q7lrv910pkbfb1lidbdfr3bkfjglui@4ax.com> <3s93q719q1787gb4ihi4fugvn8cvgc8nu2@4ax.com> <29053378.63.1336093904131.JavaMail.geo-discussion-forums@pbctc10> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 7 May 2012 17:38:18 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="WpcHJSul77m+zlbR9GVqkA"; logging-data="12999"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RGN3wWvOK+6NaNvYl22ubseAz8oeRbO8=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Cancel-Lock: sha1:fA8MGzUAAtnvefDVPR18VZVXf/o= Xref: csiph.com comp.lang.java.programmer:14372 On 5/7/2012 12:34 PM, Gene Wirchenko wrote: > Floating point can represent some integer values exactly. The > IEEE 754 64-bit format has 53 bits of precision. This is not quite 16 > digits of precision. Stick with integer values in the range > (-10^15,10^15) (an exclusive range), and they will all be represented > exactly. Or, another way to look at it, double arithmetic can represent exactly every value which would be a Java int, which means if you would normally use an int in the first place, you can use a double instead (with tweaks needed for division). Indeed, many JS JITs will do arithmetic as integers if the numbers are integral. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth