From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public X-Google-Thread: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/15 Message-ID: #1/1 X-Deja-AN: 490154708 References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <3766650F.705125B7@pwfl.com> <7k64t7$igo$1@its.hooked.net> <7k689a$ci2@drn.newsguy.com> <3766C842.E1EAB60A@pwfl.com> <3766D1CC.D712895E@itools.symantec.com> X-Complaints-To: usenet@nusku.cts.com X-Trace: nusku.cts.com 929515991 2373 198.68.168.21 (16 Jun 1999 06:53:11 GMT) Organization: CTS Network Services NNTP-Posting-Date: 16 Jun 1999 06:53:11 GMT Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-16T06:53:11+00:00 List-Id: D'Arcy Smith writes: > If you're sent into a room that is full of pins sticking up from the > floor - and you are told that it is full of pins - and you run into > the room with your eyes closed then it is 100% your fault. (I took the liberty of correcting some typos in the quoted text.) If I hire someone to build me a house, and the living room is full of pins sticking up from the floor -- and the builder clearly tells me about this feature -- it's my fault if I run into the living room with my eyes closed. But I'm going to be a bit upset with the builder for building it that way in the first place. No programming language implementation can accurately and efficiently model arithmetic on the full set of mathematical integers. (If it can't handle 10**(10**(10**100)), it's not modeling the full mathematical set.) So, some compromises are necessary, typically by guaranteeing mathematical correctness only for a limited range (32 bits, 64 bits, whatever). My favorite compromise is the one that says: For any arithmetic operation on integers, you will get the mathematically correct result if it fits in the representation; otherwise, you will be clearly informed that the implementation was unable to do so (via an exception or some similar mechanism). For most purposes, I believe this is *better* than a compromise that says, For any arithmetic operation on integers, you will get the mathematically correct result if it fits in the representation; otherwise, you will get a mathematically incorrect (but perhaps well-defined) result, with no straightforward way to detect that it's mathematically incorrect. This assumes, of course, that the abstraction you're trying to (partially) model is the mathematical set of integers -- which it usually is. Some people have argued that wraparound semantics, if they're well-defined, are as "correct" as anything else. Sorry, but I don't buy it. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> One of the great tragedies of ancient history is that Helen of Troy lived before the invention of the champagne bottle.