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,9bb56e94a4c5bb5e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone-sf.pbi.net!151.164.30.34!cyclone.swbell.net!bos-service1.raytheon.com!dfw-service2.ext.ray.com.POSTED!53ab2750!not-for-mail From: Mark H Johnson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How unchecked conversion works? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <0NSFd.2$Lz6.0@dfw-service2.ext.ray.com> Date: Fri, 14 Jan 2005 10:52:11 -0600 NNTP-Posting-Host: 192.27.48.106 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.ray.com 1105721532 192.27.48.106 (Fri, 14 Jan 2005 10:52:12 CST) NNTP-Posting-Date: Fri, 14 Jan 2005 10:52:12 CST Organization: Raytheon Company Xref: g2news1.google.com comp.lang.ada:7774 Date: 2005-01-14T10:52:11-06:00 List-Id: None wrote: > well, I try to explain. I have those types for example > > type fixed is delta 0.03 range -90.0..90.0 > for fixed'size use 16 > > and > > type inte is range -32768..32767 > for inte'size use 16 > > > and a new function that renames unchecked_conversion to come from fixed > to inte (probably an inefficient way, but I have to do this way), so I'd > like to predict on paper which value of inte type corresponds to 89.09 > for example: what kind of calculus should I do? This depends on > something else? Thanks again! The specific answer will likely be compiler specific so you may need to write a test application to verify the result. Let me see if I can explain why... One choice - the compiler chooses to represent value as 1 == your delta value (0.03) and scale everything appropriately. Then 90.0 is represented by 3000 (decimal) since 3000 * 0.03 == 90.0 So you have a range of values +/- 3000 when you do the unchecked conversion. Pretty straight forward implementation for your problem. Another choice - the compiler chooses to make 'Small of your datatype not equal to 'Delta of your data type (this IS allowed in ARM 3.5.9). Since you did not request a decimal fixed point value, 'Small will be a power of two smaller than 'Delta. If my arithmetic is correct, that could be something like 1/64 (0.015625) or even smaller (e.g., 1/256). In this case, the value could be mapped as follows: Siiiiiiiffffffff where S is the sign bit, iiiiiii is the 7 bit integer value and ffffffff is the 8 bit fraction. I assume you can do the appropriate arithmetic to interpret this form of fixed point value. To some extent this gets back to how fixed point values were represented "long ago". You could either represent them as: - values right adjusted into a register / storage location OR - values left adjusted into a register / storage location Each method has definite advantages and disadvantages when doing arithmetic - especially when considering multiplication and division. Both methods were used in the past and the Ada reference manual basically allows either to be used in this case. Your compiler should define this "implementation detail" in sufficient detail to figure out which method is used. Note however, that whatever code you use to process this will NOT be very portable between Ada compilers and target systems. --Mark