comp.lang.ada
 help / color / mirror / Atom feed
From: Mark H Johnson <mark_h_johnson@raytheon.com>
Subject: Re: How unchecked conversion works?
Date: Fri, 14 Jan 2005 10:52:11 -0600
Date: 2005-01-14T10:52:11-06:00	[thread overview]
Message-ID: <0NSFd.2$Lz6.0@dfw-service2.ext.ray.com> (raw)
In-Reply-To: <huRFd.84215$C94.3893@tornado.fastwebnet.it>

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




  parent reply	other threads:[~2005-01-14 16:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-13 18:54 How unchecked conversion works? None
2005-01-13 21:22 ` Frank J. Lhota
2005-01-13 22:28 ` Keith Thompson
2005-01-14  0:17   ` Larry Kilgallen
2005-01-14 15:23 ` None
2005-01-14 15:55   ` Marius Amado Alves
2005-01-14 22:29     ` Keith Thompson
2005-01-14 23:15       ` Marius Amado Alves
2005-01-15  1:27         ` Keith Thompson
2005-01-15  2:15         ` Larry Kilgallen
2005-01-15 10:24           ` Marius Amado Alves
2005-01-15 12:02             ` Larry Kilgallen
2005-01-15 16:54               ` Nick Roberts
2005-01-16 16:14                 ` Larry Kilgallen
2005-01-16 16:41                   ` Jeffrey Carter
2005-01-16 20:52                     ` TCSEC security levels [was: How unchecked conversion works?] Nick Roberts
2005-01-17 15:57                       ` Larry Kilgallen
2005-01-17  0:34                     ` How unchecked conversion works? Larry Kilgallen
2005-01-17  1:29                       ` Jeffrey Carter
2005-01-17  4:20                         ` Larry Kilgallen
2005-01-15 18:24             ` Jeffrey Carter
2005-01-14 16:52   ` Mark H Johnson [this message]
2005-01-14 22:27     ` Keith Thompson
2005-01-14 22:49   ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox