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,5f764f1f7822ab9c X-Google-Attributes: gid103376,public From: Bill Brennan Subject: Re: Top 10 Language Constructs (Ada) Date: 2000/07/18 Message-ID: <39751555.4E40A4A7@lmco.com>#1/1 X-Deja-AN: 647790936 Content-Transfer-Encoding: 7bit References: <8kmjja$l5h$1@pollux.ip-plus.net> <3970F56F.F3A70FAD@icdc.com> <01HW.B59982450058903A078EC70C@news.pacbell.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.vf.lmco.com X-Trace: knight.vf.lmco.com 963931173 18480 166.17.160.226 (18 Jul 2000 14:39:33 GMT) Organization: Lockheed Martin Mime-Version: 1.0 NNTP-Posting-Date: 18 Jul 2000 14:39:33 GMT Newsgroups: comp.lang.ada Date: 2000-07-18T14:39:33+00:00 List-Id: David Kristola wrote: > The other day, i came across a message field in an interface document > that i was coding against. The field is 16 bits, with the high order > bit being a sign bit, the next highest order bit has the value 2^1, > the third highest bit is 2^0, and so on down to the low order bit, > which is 2^(-13). The note said that the field is 2's complement. > No problem.... > > type Plasma_Volts_Type is delta 0.00012207 range -4.0 .. 3.99987793; > for Plasma_Volts_Type'Size use 16; Actually, this doesn't compile in GNAT, I presume because it rounds Plasma_Volts_Type'Last to something which won't fit in 16 bits. Besides the fact that this type definition isn't portable (for GNAT anyway), it doesn't really reflect what you're trying to say. Without your description, I would have no idea that 0.00012207 ~= 2^(-13) or that 3.99987793 ~= 4 - 2^(-13). Personally, I think it's clearer to state it as type Plasma_Volts_Type is delta 2#000.0_0000_0000_0001# -- approx 0.00012207 range -2#100.0_0000_0000_0000# .. -- -4 2#011.1_1111_1111_1111#; -- approx 3.99987793 for Plasma_Volts_Type'Size use 16; which will compile, and more accurately expresses what is intended. This ability to express literals fairly transparently using any numerical base of convenience is yet another reason to value Ada. (though I'm not sure it's important enough to go on my top 10 list.) -- Bill Brennan