Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 25 Jul 2011 11:30:22 -0500 Date: Mon, 25 Jul 2011 09:30:16 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <4e262731$0$314$14726298@news.sunsite.dk> <4e26300b$0$309$14726298@news.sunsite.dk> <4e26b4ed$0$2501$db0fefd9@news.zen.co.uk> <4e28097f$0$2533$da0feed9@news.zen.co.uk> <7a23c9d2-508f-4dbd-af91-8cdf2a9764e1@p29g2000pre.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <78ednRjnJuyDB7DTnZ2dnUVZ_gadnZ2d@earthlink.com> Lines: 39 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.200.239 X-Trace: sv3-4PiMWgAQEvOcsPIaVLbQwL6KPkm3okRRCzmPWjvYjKDyInOx/vuO+KqFWf/WzplqCbVl4bZP9n3YW9h!hgRZ/OS7tl4rBJG53pvu73KPRJbvWA6YxFgkMqqnIaI6Pp+bGdV2lAAYZkNIyMFxqxVhM5ujcWal!/nxXOZW5sedT/PEP38RqWYSSbmKg8XpIdQ8kOq57I8st2Oc= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3384 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6538 On 7/25/2011 9:09 AM, Patricia Shanahan wrote: ... > The key question is how "sensible" is the correspondence. We already > have some awkwardness in making Double implement Comparable and extend > Number, because Double can have Not-a-Number values. Double has to > pretend NaNs are numbers in some Comparable and Number contexts, even > though their whole point is to represent the lack of a numerical result. ... Returning to the original topic of this thread, I think one of the worst decisions in the early Java design was to treat NaN as zero on conversion to an integer type. Consider the following program: public class DivisionExample { public static void main(String[] args) { System.out.println(0.0 / 0.0); System.out.println((long) (0.0 / 0.0)); try { System.out.println(0 / 0); } catch (ArithmeticException e) { System.out.println("Integer division: " + e.getMessage()); } } } It prints: NaN 0 Integer division: / by zero If the undefined 0/0 division is done in an integer type it throws an exception. If it is done in double and the double is output as a double, it is a NaN. If the double is converted to integer, the already detected NaN condition is silently turned into a zero. Patricia