Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!news1.google.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:09:27 -0500 Date: Mon, 25 Jul 2011 09:09:21 -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: Lines: 39 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.200.239 X-Trace: sv3-kWs57NfULNconO9cUlcdBRG/CK9l3YGrx0oRFIeLvbsgiUnJUM9TAmfF6YZYwRs+pqiLNQwAqIptd/u!l4ra2WIzloIpcKwlX+RLyk0ejjj/xHTcIewncUSxo/sjHNWUgi6FTaokWyzKCCg1kviV7vQEh/8E!RD7g0z3hl1wT2MI4fIR1uxYZegAL+w/SPngnyEjvNkmAaeA= 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: 3777 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6537 On 7/25/2011 8:12 AM, Henderson wrote: > On 25/07/2011 7:06 AM, Andreas Leitgeb wrote: ... >> Simple example: what would be the sum of >> BigInteger("123456789012345678901234567890123456789012") and some >> Complex( 0.0 , Math.PI )? > > Ideally, it would be a Complex with bignum components, preserving > precision. Treat x+y as x.plus(y). Apply the usual compile and run time method invocation rules. The type of the result of x+y is the return type of x.plus(y). Report the usual errors. That strategy would require some explicit conversions but is much clearer than anything that attempts inference for user-defined arithmetic types beyond the method invocation conversions. It leaves the choice of the return type to the writers of the classes and the code using them, where it should be for generality. > Until some enterprising mathematician thinks up something that can be > added and multiplied, but has no sensible correspondence to any > subset of any kind of vectors of real numbers ... How about the symmetries of a square? Or, for that matter, any arbitrary group? If you have a group, you have addition. At one level, every practical type is limited to values that can be represented by finite bit strings, and those bit strings can all be mapped to natural numbers. 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. Patricia