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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3ccb707f4c91a5f2 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Portability of Arithmetic (was: Java vs Ada 95) Date: 1996/10/17 Message-ID: <326628B8.7724@gsfc.nasa.gov>#1/1 X-Deja-AN: 190055709 references: <325D7F9B.2A8B@gte.net> <1996Oct15.174526.1@eisner> content-type: text/plain; charset=us-ascii organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA mime-version: 1.0 reply-to: Stephen.Leake@gsfc.nasa.gov newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; U) Date: 1996-10-17T00:00:00+00:00 List-Id: Robert A Duff wrote: > > In article <1996Oct15.174526.1@eisner>, > Larry Kilgallen wrote: > >In article , bobduff@world.std.com (Robert A Duff) writes: > >> How about portability of arithmetic? In Java, int is always exactly 32 > >> bits 2's complement. In Ada, Integer is whatever the machine supports. > >> And if I say "type T is range 1..100;" I might get 32-bit arithmetic, or > >> I might get 8-bit arithmetic, or who-knows-what. > > > >And why should it matter ? If your specification is to cover that > >range, a compiler is meeting that specification even if it converts > >it to BCD to accomplish it on some _very_ old hardware. > > type T is range 1..100; > X: T := ...; > Y: T := ...; > Average: T := (X + Y) / 2; > > Because the above code will work fine on some Ada compilers, and blow up > on others (the addition will overflow using 8-bit signed arithmetic) if > X and Y happen to be, say, 99. In Java, the above code is guaranteed to > work. > > - Bob Clearly, the Ada type should be defined to cover the expected range of intermediate values, as well as the final values: type T is range 1 .. 200; What if I'm doing some computations in Java that have intermediate values that need 33 bits? In Ada, the compiler tells me when it can't do that. -- - Stephe