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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bffcdbd805329ff8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-30 19:53:46 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!sn-xit-01!supernews.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: compile time Least Common Multiple, was Re: Ada and Internet stuff References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Fri, 31 Aug 2001 02:53:45 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 999226425 24.7.82.199 (Thu, 30 Aug 2001 19:53:45 PDT) NNTP-Posting-Date: Thu, 30 Aug 2001 19:53:45 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:12602 Date: 2001-08-31T02:53:45+00:00 List-Id: This code may be so bizarre as to be whimsical, but what the heck. Problem: Given that Stream_Element'size is not necessarily 8 bits, but can be assumed to be no greater than 128 bits, declare a Stream_Element_Array subtype that is the shortest possible, but a multiple of 24 bits. -- Finding the GCD of 24 and any number from 1 .. 128 takes at most 5 -- iterations. Larger1 : constant := boolean'pos(24 > Stream_Element'size) * 24 + boolean'pos(24 <= Stream_Element'size) * Stream_Element'size; Smaller1 : constant := boolean'pos(24 > Stream_Element'size) * Stream_Element'size + boolean'pos(24 <= Stream_Element'size) * 24; R1 : constant := Larger1 mod Smaller1; Is_Zero1 : constant := boolean'pos(R1 = 0); GCD1 : constant := Is_Zero1 * Smaller1; -- Once R(n) = 0, then Is_Zero(n) = 1 and Smaller(n+1) = 0 -- so R(n+1) = Larger(n+1) mod 1 = 0. ie all following R(n+1 ...) = 0 -- and exactly one of Is_Zero(i) is non-zero Larger2 : constant := Smaller1; Smaller2 : constant := R1; R2 : constant := Larger2 mod (Smaller2 + Is_Zero1); Is_Zero2 : constant := boolean'pos(R2 = 0); GCD2 : constant := Is_Zero2 * Smaller2; Larger3 : constant := Smaller2; Smaller3 : constant := R2; R3 : constant := Larger3 mod (Smaller3 + Is_Zero2); Is_Zero3 : constant := boolean'pos(R3 = 0); GCD3 : constant := Is_Zero3 * Smaller3; Larger4 : constant := Smaller3; Smaller4 : constant := R3; R4 : constant := Larger4 mod (Smaller4 + Is_Zero3); Is_Zero4 : constant := boolean'pos(R4 = 0); GCD4 : constant := Is_Zero4 * Smaller4; Larger5 : constant := Smaller4; Smaller5 : constant := R4; R5 : constant := Larger5 mod (Smaller5 + Is_Zero4); Is_Zero5 : constant := boolean'pos(R5 = 0); GCD5 : constant := Is_Zero5 * Smaller5; GCD : constant := GCD1+GCD2+GCD3+GCD4+GCD5; -- will give the Greatest Common Divisor. -- LCM is the least common multiple of 24 bits and Stream_Element'size LCM : constant := 24*Stream_Element'size/GCD; subtype To_Encode is Stream_Element_Array(1 .. LCM/Stream_Element'size); -- To_Encode'size = LCM