comp.lang.ada
 help / color / mirror / Atom feed
* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]       ` <3f1f2f67-5d69-4baf-8e8c-0d2b5f68475f@p36g2000prp.googlegroups.com>
@ 2009-01-15 16:36         ` Adam Beneschan
       [not found]         ` <8e64f509-f6fe-4d86-ae1a-fe0b1c88555a@v5g2000pre.googlegroups.com>
       [not found]         ` <d3b7ad53-af51-4ac5-9167-7cb99e61b2b1@v5g2000pre.googlegroups.com>
  2 siblings, 0 replies; 13+ messages in thread
From: Adam Beneschan @ 2009-01-15 16:36 UTC (permalink / raw)


On Jan 15, 7:55 am, ChristopherL <clusard...@aol.com> wrote:
> After some size investigation here is what I found.
>
> Here is a program that impliments everything that I have been trying
> to do.
>
> I want to put the value of variable "Arg" into variable "Result"
> without changing
> the definitions of these two variables.
>
> Arg is a variable with 32 bits and will never be negative or greater
> than 200.
> Result is a variable of 10 bits.
>
> When I try to do it using the below program, I get the below error
> message.

The reason why the CONSTRAINT_ERROR/Range_Check error message is
happening has been explained to you, clearly, multiple times.  If you
still don't understand it, you're not going to understand it if we
tell you again.

                               -- Adam

>
> Chris L.
>
> --with Unchecked_Conversion;
>
> procedure test is
>   subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1);
>   subtype A_Float is Float;
>
>   subtype Short_integer2 is Integer range 0.. ((2 ** 8) - 1);
>   subtype A_Natural is Natural range 0..((2 ** 8) - 1);
>
>   --FYI1
>   Size_Of_Float : integer := Float'Size;                  -- 32
>   Size_Of_short_int: integer := Short_integer1'Size;      --
> 10 !!!!!!! Size is 10
>
>   --FYI2
>   Size_Of_short_integer: integer := Short_integer2'Size;  -- 8
>   Size_Of_Natural: integer := A_Natural'Size;             -- 8
>
>   Arg    : A_Float;
>   Result : Short_integer1;
> Begin
>
> Arg := 200.0;
>
> Result := Short_integer1(Arg);
>
> End test;
>
> --Run Time Error Message Follows
> Unhandled exception:
>
> CONSTRAINT_ERROR raised in MAIN
>
> Range_Check_Failed
>
> Exception raised at code address: 0x412494
> +++ Program completed with exit code 1 at 01/15/09 07:37:44
> +++
> --------------------------------------------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]         ` <8e64f509-f6fe-4d86-ae1a-fe0b1c88555a@v5g2000pre.googlegroups.com>
@ 2009-01-15 17:09           ` christoph.grein
  2009-01-15 17:17             ` Adam Beneschan
       [not found]             ` <a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com>
  2009-01-15 17:23           ` Georg Bauhaus
  1 sibling, 2 replies; 13+ messages in thread
From: christoph.grein @ 2009-01-15 17:09 UTC (permalink / raw)


On 15 Jan., 17:46, ChristopherL <clusard...@aol.com> wrote:
> Can some the Ada intelligent person modify this program to make it
> correctly
> put the value in variable "Arg" into the variable "Result".

Can anybody please help me to seat 200 people in a bus with 127 seats.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
  2009-01-15 17:09           ` christoph.grein
@ 2009-01-15 17:17             ` Adam Beneschan
  2009-01-15 17:29               ` Georg Bauhaus
       [not found]             ` <a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com>
  1 sibling, 1 reply; 13+ messages in thread
From: Adam Beneschan @ 2009-01-15 17:17 UTC (permalink / raw)


On Jan 15, 9:09 am, christoph.gr...@eurocopter.com wrote:
> On 15 Jan., 17:46, ChristopherL <clusard...@aol.com> wrote:
>
> > Can some the Ada intelligent person modify this program to make it
> > correctly
> > put the value in variable "Arg" into the variable "Result".
>
> Can anybody please help me to seat 200 people in a bus with 127 seats.

Vaseline?

Actually, on second thought, maybe just get some bungee cords and tie
73 people to the roof.

                                -- Adam




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]         ` <8e64f509-f6fe-4d86-ae1a-fe0b1c88555a@v5g2000pre.googlegroups.com>
  2009-01-15 17:09           ` christoph.grein
@ 2009-01-15 17:23           ` Georg Bauhaus
  1 sibling, 0 replies; 13+ messages in thread
From: Georg Bauhaus @ 2009-01-15 17:23 UTC (permalink / raw)


ChristopherL schrieb:
> Can some the Ada intelligent person modify this program to make it
> correctly
> put the value in variable "Arg" into the variable "Result".

Yes, anyone here can.  A possibly hint is this:
Of what type is your Result variable (look closely)?
Note the values that can be assigned to
variable Result, accordingly.
Is the converted value of floating point value 200.0
in this range of values?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
  2009-01-15 17:17             ` Adam Beneschan
@ 2009-01-15 17:29               ` Georg Bauhaus
       [not found]                 ` <09b4a056-688d-49c8-b935-fa0b30f1ae84@w1g2000prk.googlegroups.com>
       [not found]                 ` <97231951-54a0-4df7-bb73-04261b34287f@e6g2000vbe.googlegroups.com>
  0 siblings, 2 replies; 13+ messages in thread
From: Georg Bauhaus @ 2009-01-15 17:29 UTC (permalink / raw)


Adam Beneschan schrieb:
> On Jan 15, 9:09 am, christoph.gr...@eurocopter.com wrote:
>> On 15 Jan., 17:46, ChristopherL <clusard...@aol.com> wrote:
>>
>>> Can some the Ada intelligent person modify this program to make it
>>> correctly
>>> put the value in variable "Arg" into the variable "Result".
>> Can anybody please help me to seat 200 people in a bus with 127 seats.
> 
> Vaseline?
> 
> Actually, on second thought, maybe just get some bungee cords and tie
> 73 people to the roof.


http://www.tropicalisland.de/india/rajasthan/karauli/pages/JAI%20-%20local%20bus%20truck%20with%20people%20on%20the%20roof%20on%20the%20road%20from%20Ranthambore%20National%20Park%20to%20Karauli%203008x2000.html



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]         ` <d3b7ad53-af51-4ac5-9167-7cb99e61b2b1@v5g2000pre.googlegroups.com>
@ 2009-01-15 17:50           ` Stuart
  0 siblings, 0 replies; 13+ messages in thread
From: Stuart @ 2009-01-15 17:50 UTC (permalink / raw)


"ChristopherL" <clusardi2k@aol.com> wrote in message 
news:d3b7ad53-af51-4ac5-9167-7cb99e61b2b1@v5g2000pre.googlegroups.com...
On Jan 15, 7:55 am, ChristopherL <clusard...@aol.com> wrote:
> After some size investigation here is what I found.

<snip>

> I want to put the value of variable "Arg" into variable "Result"
> without changing the definitions of these two variables.
>
> Arg is a variable with 32 bits and will never be negative or greater
> than 200.
> Result is a variable of 10 bits.

This is not really relevant, but to anything you have defined as a 
requirement (because you do not explicitly specify you want these sizes, 
they just happen to be what the system chose for you).

> When I try to do it using the below program, I get the below error
> message.
...
> procedure test is
> subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1);

rewriting this
   subtype Short_integer1 is integer range -128..127;

> subtype A_Float is Float;

<snip>

> Arg : A_Float;
> Result : Short_integer1;
> Begin
>
> Arg := 200.0;
>
> Result := Short_integer1(Arg);

Given that you have declared Short_integer1 to have a range of -128..127 
what value do you think should be put in Result when you provide a value of 
200.0?

Are you, perhaps expecting wrap-around semantics?

   if (Arg > A_float(Short_integer1'last)) then
      Result := Short_integer1(A_float(Short_integer1'last) - Arg);
  else
      Result := Short_integer1(Arg);
  end if;

> End test;


> Can Ada intelligent person modify this program to make it correctly
> put the value in variable "Arg" into the variable "Result".

At the moment I would say no as we do not know how you think the 
contradiction of Result being in the -128..127 and you wanting the value 200 
should be resolved.

Ada is doing what it is meant to do and pointing out to you that the current 
behaviour is in error because you are exceeding the constraints (range of 
legal values) of Result.

As there seems to be some difficulty communicating requirements in terms 
that both parties can understand, perhaps you can clarify your requirement 
by indicating what values you expect for a number of cases bearing in mind 
that with your current definition (which you don't want to change) Result 
must be an integer value in the range -128..127:

    Arg       Result
    0.00
    0.49
    0.50
    0.51
    1.00
    1.49
    1.50
    1.51
126.50
126.51
127.00
127.01
127.49
127.50
127.51
128.00
199.49
199.50
199.51
199.99
200.00

-- 
Stuart 





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]             ` <a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com>
@ 2009-01-15 18:15               ` Martin
  2009-01-15 18:34               ` Stuart
  1 sibling, 0 replies; 13+ messages in thread
From: Martin @ 2009-01-15 18:15 UTC (permalink / raw)


On Jan 15, 5:21 pm, ChristopherL <clusard...@aol.com> wrote:
> On Jan 15, 9:09 am, christoph.gr...@eurocopter.com wrote:
>
> > On 15 Jan., 17:46, ChristopherL <clusard...@aol.com> wrote:
>
> > > Can some the Ada intelligent person modify this program to make it
> > > correctly
> > > put the value in variable "Arg" into the variable "Result".
>
> > Can anybody please help me to seat 200 people in a bus with 127 seats.
>
> But, isn't 2^10 greater than 200! So, is there some way to put 200.0
> into the variable "Result".
>
> Ideally, if I achieve my ultimate goal I would like to later look at
> "Result" and be able to reconstruct "Arg" (200.0) from what is in
> "Result".
>
> Chris L.

2^10 is but that's not what you asked for!!!! At least not the 1st
post I saw from you!!!

E.g. from your 'test' procedure:

subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1);

That's the range -128 to 127. "200.0" isn't in that range =>
exception.

But this new 'requirement' to be able to go between a float and a 10-
bit integer representation without loosing information is just pie in
the sky!

Float value    => 10.12312
As 10-bit int  => 10
Back to float  => 10.00000

That why computer have different data types and why programming
languages have different types to make use of them.

Or are you saying that all the floating point values will have ".0" as
their fractional part?

Is this any closer to what you want?

with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
   type UInt10 is mod 2 ** 10;
   for UInt10'Size use 10;

   type Float32 is new Float;
   pragma Assert (Float'Size = 32);

   function To_Uint10 (F : Float32) return UInt10 is
   begin
      pragma Assert (F in 0.0 .. 200.0);
      return UInt10 (F);
   end To_Uint10;

   function To_Float32 (U : UInt10) return Float32 is
   begin
      return Float32 (U);
   end To_Float32;

   procedure Test_Value (Arg : Float32) is
      package Float32_IO is new Float_IO (Float32);
      package UInt10_IO  is new Modular_IO (UInt10);
      Result     : constant UInt10  := To_Uint10 (Arg);
      Back_Again : constant Float32 := To_Float32 (Result);
   begin
      Put ("Arg        =");
      Float32_IO.Put (Arg, Fore => 4, Aft => 3);
      New_Line;
      Put ("Result     =");
      UInt10_IO.Put (Result, Width => 4);
      New_Line;
      Put ("Back_Again =");
      Float32_IO.Put (Back_Again, Fore => 4, Aft => 3);
      New_Line;
   end Test_Value;
begin
   Put_Line ("UInt10'Size  =" & Integer'Image (UInt10'Size));
   Put_Line ("Float32'Size =" & Integer'Image (Float32'Size));
   Test_Value (200.0);
   Test_Value (200.5);
end Test;

C:\Ada\test\lib\test
UInt10'Size  = 10
Float32'Size = 32
Arg        =   2.000E+02
Result     = 200
Back_Again =   2.000E+02
Arg        =   2.005E+02
Result     = 201
Back_Again =   2.010E+02

Cheers
-- Martin



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]             ` <a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com>
  2009-01-15 18:15               ` Martin
@ 2009-01-15 18:34               ` Stuart
  1 sibling, 0 replies; 13+ messages in thread
From: Stuart @ 2009-01-15 18:34 UTC (permalink / raw)


"ChristopherL" <clusardi2k@aol.com> wrote in message 
news:a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com...
> On Jan 15, 9:09 am, christoph.gr...@eurocopter.com wrote:
> > On 15 Jan., 17:46, ChristopherL <clusard...@aol.com> wrote:
> >
> > > Can some the Ada intelligent person modify this program to make it
> > > correctly
> > > put the value in variable "Arg" into the variable "Result".
> >
> > Can anybody please help me to seat 200 people in a bus with 127 seats.
>
> But, isn't 2^10 greater than 200!

Yes it is.

>  So, is there some way to put 200.0 into the variable "Result".

Not in a way that means Result has the value 200 because the declared type 
of Result (Short_integer1) is specified as having the range  -128..127.  If 
you want Result to hold values in the range 0..200 you need to declare its 
type accordingly.

> Ideally, if I achieve my ultimate goal I would like to later look at
> "Result" and be able to reconstruct "Arg" (200.0) from what is in
> "Result".

You don't say to what precision you want Arg to be restored - it would seem 
that you are only expecting to get whole number values.  In which case, if 
you are wanting to keep all your definitions as they are, you might best be 
doing wrap around during the conversions.  For example:
     if (Arg > 127.0) then
         Result := Short_integer1(127.0 - Arg);
     else
         Result := Short_integer1(Arg);
    end if:

    if (Result < 0) then
       Arg := A_float(127 - Result);
          -- I think the calculation will be done in the base type of Result 
(integer),
          -- if not you can use integer'(result) to be exlicit about it.
    else
       Arg := A_float(Result);
   end if;

Of course, you should comment heavily to explain this odd-ball coding and 
why you don't simply declare the type to be in the range 0..200.

Regards
-- 
Stuart 





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]                 ` <09b4a056-688d-49c8-b935-fa0b30f1ae84@w1g2000prk.googlegroups.com>
@ 2009-01-15 18:40                   ` Mike H
       [not found]                     ` <be26729d-9458-42fa-8c8c-004ca33b790d@f33g2000vbf.googlegroups.com>
  0 siblings, 1 reply; 13+ messages in thread
From: Mike H @ 2009-01-15 18:40 UTC (permalink / raw)


In message 
<09b4a056-688d-49c8-b935-fa0b30f1ae84@w1g2000prk.googlegroups.com>, 
ChristopherL <clusardi2k@aol.com> writes
>Well since I do not seem to be able to achieve what I want.
>
>Can someone tell me how to set a high order bit of a 10 number.
>
>if (arg > 128.0) then
>   arg := arg - 128.0;
>   -- set high order bit of arg maintaining all other bits
>end if;
>
>Chris L.
type Ten_Bit_Type is array (1..10) of Boolean;
for Ten_Bit_Type'Size use 10;

Ten_Bits : Ten_Bit_Type;

-- use Unchecked_Conversions to convert Arg to Ten Bits

Ten_Bits(1) := True;

-- use Unchecked_Conversions to convert Ten Bits back to Arg

-- 
Mike Hopkins
Project Rheilffordd Eryri
WHR <http://www.welshhighlandrailway.net/>




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
@ 2009-01-15 20:48 Martin
       [not found] ` <8a7769ad-133f-4587-9239-34ce90978aa1@v38g2000yqb.googlegroups.com>
  0 siblings, 1 reply; 13+ messages in thread
From: Martin @ 2009-01-15 20:48 UTC (permalink / raw)


On Jan 15, 8:15 pm, ChristopherL <clusard...@aol.com> wrote:
> How can I be getting the below error message with
> "Unchecked_Conversion".
> Isn't Unchecked_conversion just suppose to copy bits?
[snip]

...of objects of the same size.

Here's a clue...Short_integer2 is either 8-bits or 32-bits (assuming
x86) but it sure as hell ain't 10.

And try and stop "thinking in C". Ada (and other non-C based
languages) tend to have different ways of doing things. "When in Rome,
do as the Romans"

Cheers
-- Martin





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]                     ` <be26729d-9458-42fa-8c8c-004ca33b790d@f33g2000vbf.googlegroups.com>
@ 2009-01-15 20:57                       ` Niklas Holsti
  0 siblings, 0 replies; 13+ messages in thread
From: Niklas Holsti @ 2009-01-15 20:57 UTC (permalink / raw)


ChristopherL wrote:
> How can I be getting the below error message with
> "Unchecked_Conversion".
> Isn't Unchecked_conversion just suppose to copy bits?

Perhaps because your Ada compiler applies the Ada 95 rules, in 
which a call of (an instance of) Unchecked_Conversion is 
"erroneous" if the result is a scalar with an "invalid 
representation" (RM95 13.9.1(12)). In your program, the assignment 
statement

    Result2 := Get_Bits (Result1);

applies Get_Bits to Result1, which has the value 201, so Get_Bits 
tries to return a Short_integer2 with the value 201, which is 
outside the range of Short_integer2 and so is an invalid 
representation. Your compiler may signal this error by raising the 
exception (but "erroneous" execution can have any result, in 
principle).

Under the Ada 2005 rules, you can get away with this assignment -- 
it is not "erroneous" -- but the only thing you can then do with 
Result2 is to check if it is 'Valid (RM05 13.9.1(12/2)); all other 
uses of Result2 are "erroneous" (until it is assigned some valid 
value).

One way to avoid this error is to remove the range constraints on 
Short_integer2, or widen them to include 201. However, even after 
reading all of this thread I don't understand what you want to 
achieve, so I don't know what to suggest -- except to ask your boss 
for a clearer statement of the problem.

> 
> Chris L.
> with Unchecked_Conversion;
> 
> procedure test is
>   subtype Short_integer1 is Natural range 0.. ((2 ** 10) - 1);
>   subtype Short_integer2 is Integer range -(2 ** 7)..((2 ** 7) - 1);
> 
>   subtype A_Float is Float;
> 
>   subtype A_Natural is Natural range 0..((2 ** 8) - 1);
>   -- The next line (if used) gives compilation error message:
> A_NATURAL does not denote a first subtype
>   --for A_Natural'Size use Short_integer1'Size;
> 
>   Size_Of_Float : integer := Float'Size;                  -- 32
> 
>   Size_Of_short_integer: integer := Short_integer1'Size;  -- 10 bits
> long
>   Size_Of_short_int: integer := Short_integer2'Size;      -- 10 bits
> long
> 
>   Size_Of_Natural: integer := A_Natural'Size;             -- 8
> 
>   Arg     : A_Float;
>   Result2 : Short_integer2;
>   Result1 : Short_integer1;
> 
>   function Get_Bits is new Unchecked_Conversion (Source =>
> Short_integer1, Target => Short_integer2);
> 
> Begin
> 
> Arg := 200.0;
> 
> Result1 := Short_integer1(Arg + 0.5);  -- Result1 becomes 201
> Result2 := Get_Bits (Result1);
> 
> End test;
> 
> -- Error Message
> +++ Program  started at 01/15/09 12:14:02
> 
> Unhandled exception:
> 
> CONSTRAINT_ERROR raised in MAIN
> 
> Range_Check_Failed
> 
> Exception raised at code address: 0x413516
> +++ Program completed with exit code 1 at 01/15/09 12:14:02
> +++
> --------------------------------------------------------------------------------------------------------------

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found]                 ` <97231951-54a0-4df7-bb73-04261b34287f@e6g2000vbe.googlegroups.com>
@ 2009-01-16  3:17                   ` Steve D
  0 siblings, 0 replies; 13+ messages in thread
From: Steve D @ 2009-01-16  3:17 UTC (permalink / raw)


"ChristopherL" <clusardi2k@aol.com> wrote in message 
news:97231951-54a0-4df7-bb73-04261b34287f@e6g2000vbe.googlegroups.com...
> If it is not possible to do what I want.
>
> Can someone modify the below program to show me how to set a high
> order bit of a
> 10 number number, and also maintain all other bits.
>
> procedure test2 is
>
> subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1);
>
> arg:float;
> Result:Short_integer1;
>
> begin
>
> arg := 200.0
>
> if (arg > 128.0) then
>
>   arg := arg - 128.0;
>   --Result := ?;
>
> else
>
>   Result := Short_integer1(arg);
>
> end if;
>
> end test2;
>
> In this example I would like Result to have a bit representation such
> as:
>
> 10  0100  1000
>
> If you have a simplier algorithm (implemented) please share it with
> me.
>
> Thanks,
> Chris L.
>
>

See if this does what you want:

with Interfaces;
use Interfaces;
with Ada.Unchecked_Conversion;
with Ada.Text_IO;
with Ada.Float_Text_IO;

procedure TestSteve is

    subtype Short_Integer is Integer range -128..127;

    package Short_Io is new Ada.Text_Io.Integer_IO( Short_Integer );
    package Unsigned_8_Io is new Ada.Text_Io.Modular_IO( Unsigned_8 );

    function Float_To_Short_Integer( value : float ) return Short_Integer is
        function Conv is new Ada.Unchecked_Conversion( Unsigned_8, 
Short_Integer );
    begin
 return Conv( Unsigned_8( value ) );
    end Float_To_Short_Integer;

    procedure TestValue( value : float ) is
        result : Short_Integer;
 function Conv is new Ada.Unchecked_Conversion( Short_Integer, Unsigned_8 );
    begin
      result := Float_To_Short_Integer( value );
      Ada.Float_Text_IO.Put( value, 3, 1, 0 );
      Ada.Text_IO.Put( " => ");
      Short_IO.Put( Float_To_Short_Integer( value ) );
      Ada.Text_IO.Put( " => ");
      Unsigned_8_IO.Put( Conv( Float_To_Short_Integer( value ) ), 4, 2 );
      Ada.Text_IO.New_Line;
    end TestValue;

begin
    TestValue( 0.0 );
    TestValue( 127.0);
    TestValue( 200.5 );
end TestSteve;

Output:

  0.0 =>    0 => 2#0#
127.0 =>  127 => 2#1111111#
200.5 =>  -55 => 2#11001001#

Regards,
Steve 




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included)
       [not found] ` <8a7769ad-133f-4587-9239-34ce90978aa1@v38g2000yqb.googlegroups.com>
@ 2009-01-22  1:30   ` Keith Thompson
  0 siblings, 0 replies; 13+ messages in thread
From: Keith Thompson @ 2009-01-22  1:30 UTC (permalink / raw)


ChristopherL <clusardi2k@aol.com> writes:
> On Jan 15, 12:48 pm, Martin <martin.do...@btopenworld.com> wrote:
>> On Jan 15, 8:15 pm, ChristopherL <clusard...@aol.com> wrote:
> How can I be getting the below error message with
>> > "Unchecked_Conversion".
>> > Isn't Unchecked_conversion just suppose to copy bits?
>>
>> [snip]
>>
>> ...of objects of the same size.
>>
>> Here's a clue...Short_integer2 is either 8-bits or 32-bits (assuming
>> x86) but it sure as hell ain't 10.
>>
>
> When I look at "Short_integer2'Size" with the debugger it shows me 10!

That's the size of the type, not the size of an object of the type.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2009-01-22  1:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-15 20:48 How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included) Martin
     [not found] ` <8a7769ad-133f-4587-9239-34ce90978aa1@v38g2000yqb.googlegroups.com>
2009-01-22  1:30   ` Keith Thompson
     [not found] <407ae64d-3cb3-4310-b59e-f1bbae9910a5@t39g2000prh.googlegroups.com>
2009-01-14  1:33 ` How to put 200 into an integer sub-type of 16 bits (code included) Brian Drummond
2009-01-14 21:09   ` sjw
2009-01-15 14:44     ` Brian Drummond
     [not found]       ` <3f1f2f67-5d69-4baf-8e8c-0d2b5f68475f@p36g2000prp.googlegroups.com>
2009-01-15 16:36         ` How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included) Adam Beneschan
     [not found]         ` <8e64f509-f6fe-4d86-ae1a-fe0b1c88555a@v5g2000pre.googlegroups.com>
2009-01-15 17:09           ` christoph.grein
2009-01-15 17:17             ` Adam Beneschan
2009-01-15 17:29               ` Georg Bauhaus
     [not found]                 ` <09b4a056-688d-49c8-b935-fa0b30f1ae84@w1g2000prk.googlegroups.com>
2009-01-15 18:40                   ` Mike H
     [not found]                     ` <be26729d-9458-42fa-8c8c-004ca33b790d@f33g2000vbf.googlegroups.com>
2009-01-15 20:57                       ` Niklas Holsti
     [not found]                 ` <97231951-54a0-4df7-bb73-04261b34287f@e6g2000vbe.googlegroups.com>
2009-01-16  3:17                   ` Steve D
     [not found]             ` <a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com>
2009-01-15 18:15               ` Martin
2009-01-15 18:34               ` Stuart
2009-01-15 17:23           ` Georg Bauhaus
     [not found]         ` <d3b7ad53-af51-4ac5-9167-7cb99e61b2b1@v5g2000pre.googlegroups.com>
2009-01-15 17:50           ` Stuart

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