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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b9a38a75a50e726,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!feeder.erje.net!aioe.org!not-for-mail From: Dennis Hoppe Newsgroups: comp.lang.ada Subject: Feature or Bug? 2#1111# shifted by 4 is 224 Date: Mon, 02 Jun 2008 17:17:19 +0200 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: rfxIqsNOOcYSVIzBT0cW8Q.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) Xref: g2news1.google.com comp.lang.ada:525 Date: 2008-06-02T17:17:19+02:00 List-Id: Hi, we probably found a bug in Ada or we cannot realize, that this is indeed a feature ;) In Example A, we defined a simple modular shift to the left by means of Item * 2**N. N is defined as an Integer. This example works well and Shift_Left(2#1111#, 4) returns 0. -- Example A type Modular_Type is mod 2**4; function Shift_Left (Item : in Modular_Type; N : in Integer) return Modular_Type is begin return Item * 2**N; end Shift_Left; In Example B, we limit the parameter N to Positive, because we do not want "negative" shifts. The result of Shift_Left(2#1111#, 4) is 224 (2#11100000#) ! -- Example B type Modular_Type is mod 2**4; function Shift_Left (Item : in Modular_Type; N : in Positive) return Modular_Type is begin return Item * 2**N; end Shift_Left; Why does this happen? Positive is defined as all Integer values starting at 1 through the highest value of Integer, so the result should also be 0. Especially, because the returning value is additionally limited by mod 2**4. Thanks, Dennis Hoppe