comp.lang.ada
 help / color / mirror / Atom feed
* how to safely convert from 32 to 16 bits?
@ 2005-06-04 17:23 Sebastian
  2005-06-04 17:53 ` Pascal Obry
  2005-06-05  1:24 ` David C. Hoos, Sr.
  0 siblings, 2 replies; 6+ messages in thread
From: Sebastian @ 2005-06-04 17:23 UTC (permalink / raw)


Hi,

Ho do I convert a larger variable like Integer to an smaller type
without loosing any data?

What I would like to do is:

I have a variable of Integer_32 size, I also know that the value is
always between -180 and 180. I would like to assign that value to a 16
bits Real type.

How can that be done without loosing any data?

regards

/Sebastian



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

* Re: how to safely convert from 32 to 16 bits?
  2005-06-04 17:23 how to safely convert from 32 to 16 bits? Sebastian
@ 2005-06-04 17:53 ` Pascal Obry
  2005-06-04 18:45   ` Robert Klungle
  2005-06-05  1:24 ` David C. Hoos, Sr.
  1 sibling, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2005-06-04 17:53 UTC (permalink / raw)



di98mase@hotmail.com (Sebastian) writes:

> I have a variable of Integer_32 size, I also know that the value is
> always between -180 and 180. I would like to assign that value to a 16
> bits Real type.
> 
> How can that be done without loosing any data?

I don't see the problem.

   A : Integer_32;
   B : Integer_16:

   B := Integer_16 (A);

Since A is always between -180 and 180 there will be no exception raised.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: how to safely convert from 32 to 16 bits?
  2005-06-04 17:53 ` Pascal Obry
@ 2005-06-04 18:45   ` Robert Klungle
  2005-06-05  8:13     ` Pascal Obry
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Klungle @ 2005-06-04 18:45 UTC (permalink / raw)


Unless I misread the requestor, I think the following would more direct:

A : Integer_32;
B : Real_16;

B := Real_16(A);

cheers...bob

"Pascal Obry" <pascal@obry.net> wrote in message
news:uk6la101m.fsf@obry.net...
>
> di98mase@hotmail.com (Sebastian) writes:
>
> > I have a variable of Integer_32 size, I also know that the value is
> > always between -180 and 180. I would like to assign that value to a 16
> > bits Real type.
> >
> > How can that be done without loosing any data?
>
> I don't see the problem.
>
>    A : Integer_32;
>    B : Integer_16:
>
>    B := Integer_16 (A);
>
> Since A is always between -180 and 180 there will be no exception raised.
>
> Pascal.
>
> -- 
>
> --|------------------------------------------------------
> --| Pascal Obry                           Team-Ada Member
> --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
> --|------------------------------------------------------
> --|              http://www.obry.net
> --| "The best way to travel is by means of imagination"
> --|
> --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595





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

* Re: how to safely convert from 32 to 16 bits?
  2005-06-04 17:23 how to safely convert from 32 to 16 bits? Sebastian
  2005-06-04 17:53 ` Pascal Obry
@ 2005-06-05  1:24 ` David C. Hoos, Sr.
  2005-06-05  5:03   ` Keith Thompson
  1 sibling, 1 reply; 6+ messages in thread
From: David C. Hoos, Sr. @ 2005-06-05  1:24 UTC (permalink / raw)
  To: Sebastian; +Cc: comp.lang.ada

What compiler and hardware are you using that has a 16-bit Real type?

----- Original Message ----- 
From: "Sebastian" <di98mase@hotmail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: June 04, 2005 12:23 PM
Subject: how to safely convert from 32 to 16 bits?


> Hi,
> 
> Ho do I convert a larger variable like Integer to an smaller type
> without loosing any data?
> 
> What I would like to do is:
> 
> I have a variable of Integer_32 size, I also know that the value is
> always between -180 and 180. I would like to assign that value to a 16
> bits Real type.
> 
> How can that be done without loosing any data?
> 
> regards
> 
> /Sebastian
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 
>



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

* Re: how to safely convert from 32 to 16 bits?
  2005-06-05  1:24 ` David C. Hoos, Sr.
@ 2005-06-05  5:03   ` Keith Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Thompson @ 2005-06-05  5:03 UTC (permalink / raw)


"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:
> "Sebastian" <di98mase@hotmail.com> writes:
>> Ho do I convert a larger variable like Integer to an smaller type
>> without loosing any data?
>> What I would like to do is:
>> I have a variable of Integer_32 size, I also know that the value is
>> always between -180 and 180. I would like to assign that value to a 16
>> bits Real type.
>> How can that be done without loosing any data?
> 
> What compiler and hardware are you using that has a 16-bit Real type?

It could be a fixed-point type.  If so, knowing that it's 16 bits
doesn't necessarily tell us that it can hold all values from -180 to
180.

To the original poster: How exactly is Real declared?

If the target type can hold all the expected values, just do a
conversion.  If it can't, there's nothing you can do to make all the
values fit (unless you change the type).

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.



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

* Re: how to safely convert from 32 to 16 bits?
  2005-06-04 18:45   ` Robert Klungle
@ 2005-06-05  8:13     ` Pascal Obry
  0 siblings, 0 replies; 6+ messages in thread
From: Pascal Obry @ 2005-06-05  8:13 UTC (permalink / raw)



"Robert Klungle" <bklungle@adelphia.net> writes:

> Unless I misread the requestor, I think the following would more direct:
> 
> A : Integer_32;
> B : Real_16;
> 
> B := Real_16(A);

I see the OP want to convert from Real type to Integer_32 without loosing data.

Now it would be nice to know what is meant by "loosing no data" ? How many
digits for example ?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

end of thread, other threads:[~2005-06-05  8:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-04 17:23 how to safely convert from 32 to 16 bits? Sebastian
2005-06-04 17:53 ` Pascal Obry
2005-06-04 18:45   ` Robert Klungle
2005-06-05  8:13     ` Pascal Obry
2005-06-05  1:24 ` David C. Hoos, Sr.
2005-06-05  5:03   ` Keith Thompson

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