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: 103376,fee8802cc3d8334d X-Google-Attributes: gid103376,public X-Google-Thread: 10a146,fee8802cc3d8334d X-Google-Attributes: gid10a146,public From: Matthew Heaney Subject: Re: Ada and Java. different behaviour. casting long to int problem. Date: 1999/06/17 Message-ID: #1/1 X-Deja-AN: 490555201 References: <7jt2c0$vrb@drn.newsguy.com> <7k57vb$1ipf@drn.newsguy.com> <37667A00.2086E4F8@itools.symantec.com> <3767D597.8C77A423@cajunbro.com> NNTP-Posting-Date: Wed, 16 Jun 1999 23:04:37 PDT Newsgroups: comp.lang.ada,comp.lang.java.programmer Date: 1999-06-17T00:00:00+00:00 List-Id: On 16 Jun 1999 11:49, "George W. Bayles" wrote: > That reminds me - using scaled integers to represent angles > > int theta = (int) MAX_INT*(theta_degrees/180.0); > > makes adding and subtracting angles much nicer because of the wrap > around! It is a feature of computer integers that they are more like a > compass than a ruler. You can do this in Ada already: with System; package Angle_Types is type Angle_In_Deg_Type_Base is delta 1024.0 * System.Fine_Delta range -1024.0 .. 1024.0; for Angle_In_Deg_Type_Base'Small use 1024.0 * System.Fine_Delta; subtype Angle_In_Deg_Type is Angle_In_Deg_Type_Base range 0.0 .. Angle_In_Deg_Type_Base'Pred (360.0); function "+" (L, R : Angle_In_Deg_Type) return Angle_In_Deg_Type; function "-" (L, R : Angle_In_Deg_Type) return Angle_In_Deg_Type; end Angle_Types; The addition and substraction operators are defined to have wrap-around semantics. This captures the angle abstraction perfectly, and we don't have to go mucking around with hacks like "scaled integers."