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,f822ae7b0f7433c1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.germany.com!newsfeed.freenet.de!news.tiscali.de!tiscali!newsfeed1.ip.tiscali.net!fi.sn.net!newsfeed2.fi.sn.net!news.song.fi!not-for-mail Date: Tue, 16 Jan 2007 14:15:52 +0200 From: Niklas Holsti User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20060628 Debian/1.7.8-1sarge7.1 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Translating an embedded C algorithm References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <45acc0c3$0$22514$39db0f71@news.song.fi> Organization: TDC Song Internet Services NNTP-Posting-Host: laku61.adsl.netsonic.fi X-Trace: 1168949443 news.song.fi 22514 81.17.205.61:32910 X-Complaints-To: abuse@song.fi Xref: g2news2.google.com comp.lang.ada:8163 Date: 2007-01-16T14:15:52+02:00 List-Id: Vo, Anh (US SSA) wrote: > -----Original Message----- > <<<... > If you are interested, I have placed the section of the book here: > > http://homepages.which.net/~paul.hills/Temporary/Temperature.pdf > > so you can see the code and description. Please email me if you are > interested to paul (dot) hills (who is at) uk (dot) landisgyr (dot) > com. >>> > > Here I just translated directory to Ada from C code in the table. Please pay attention to the Important Note below the Table. Note also that I have slightly modified some variables for readability. Let me know if more information is desired. > > ... > -- ... Since the spacing is a power of 2, > -- this can be achieved by simply masking all but the bottom 3 bits. > InterpolationDistance := (Adc_Count - MINIMUM_ADC_COUNT) + (SPACING - 1); ^^^ Mistake: That "+" is a bit-wise logical AND operation (&) in the C code. We could use modular types, but if (as noted later in the C code) the compiler is clever enough to implement division by 8 with shifting, it should also be clever enough to implement "mod 8" as masking, so the Ada code could be simply "mod Spacing". I agree with other posters that simply translating this function into Ada does not give a good comparison between C and Ada. The first steps in an Ada design would be to consider encapsulation (packages) and data representation (types), for which the C version gives no model. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .