comp.lang.ada
 help / color / mirror / Atom feed
* Conversion from floating point to signed 16 bits
@ 2009-05-19 18:51 Olivier Scalbert
  2009-05-19 19:37 ` Adam Beneschan
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Olivier Scalbert @ 2009-05-19 18:51 UTC (permalink / raw)


Hello,

My problem:
I need to convert an "analogic" value which can vary from 0.0 to 1.0 
into a "discrete" value which is a signed 16 bits integer.

My implementation:
-----------------------------
with Ada.Text_IO;

procedure convert is
     type Analog_Value is digits 10 range 0.0 .. 1.0;
     type Signed_16    is range -32768 .. 32767;
     type Unsigned_16  is range      0 .. 65535;

     function Cv(Value: Analog_Value) return Signed_16 is
         U16: Unsigned_16;
     begin
         U16 := Unsigned_16(65535.0 * Value);
         return Signed_16(U16 - 32768);
     end Cv;

     procedure Put(S16: Signed_16) is
     begin
         Ada.Text_IO.Put_Line(Signed_16'image(S16));
     end put;
begin
    Put(Cv(0.00)); -- Must be -32768
    Put(Cv(0.25)); -- Must be -16384
    Put(Cv(0.50)); -- Must be      0
    Put(Cv(0.75)); -- Must be  16383
    Put(Cv(1.00)); -- Must be  32767
end convert;
-----------------------------

My question:
Is there an other way to do this in Ada (Representation ? Other parts of 
Ada I do not know ?)

My thanks:
Thank you very much !
;-)

Olivier.




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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
@ 2009-05-19 19:37 ` Adam Beneschan
  2009-05-19 19:57   ` Jeffrey R. Carter
  2009-05-19 19:55 ` Jeffrey R. Carter
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Adam Beneschan @ 2009-05-19 19:37 UTC (permalink / raw)


On May 19, 11:51 am, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Hello,
>
> My problem:
> I need to convert an "analogic" value which can vary from 0.0 to 1.0
> into a "discrete" value which is a signed 16 bits integer.
>
> My implementation:
> -----------------------------
> with Ada.Text_IO;
>
> procedure convert is
>      type Analog_Value is digits 10 range 0.0 .. 1.0;
>      type Signed_16    is range -32768 .. 32767;
>      type Unsigned_16  is range      0 .. 65535;
>
>      function Cv(Value: Analog_Value) return Signed_16 is
>          U16: Unsigned_16;
>      begin
>          U16 := Unsigned_16(65535.0 * Value);
>          return Signed_16(U16 - 32768);
>      end Cv;
>
>      procedure Put(S16: Signed_16) is
>      begin
>          Ada.Text_IO.Put_Line(Signed_16'image(S16));
>      end put;
> begin
>     Put(Cv(0.00)); -- Must be -32768
>     Put(Cv(0.25)); -- Must be -16384
>     Put(Cv(0.50)); -- Must be      0
>     Put(Cv(0.75)); -- Must be  16383
>     Put(Cv(1.00)); -- Must be  32767
> end convert;
> -----------------------------
>
> My question:
> Is there an other way to do this in Ada (Representation ? Other parts of
> Ada I do not know ?)

If your problem is that you're getting a Constraint_Error when the
subtraction "U16 - 32768" has a negative result, you can convert U16
to some larger integer type before doing the subtraction:

  return Signed_16(Signed_32(U16) - 32768);

                              -- Adam




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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
  2009-05-19 19:37 ` Adam Beneschan
@ 2009-05-19 19:55 ` Jeffrey R. Carter
  2009-05-19 20:06 ` Ludovic Brenta
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2009-05-19 19:55 UTC (permalink / raw)


Olivier Scalbert wrote:
> 
> My question:
> Is there an other way to do this in Ada (Representation ? Other parts of 
> Ada I do not know ?)

Of course there are other ways to do it. But this looks like a good way.

-- 
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
61



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 19:37 ` Adam Beneschan
@ 2009-05-19 19:57   ` Jeffrey R. Carter
  2009-05-19 22:36     ` Adam Beneschan
  0 siblings, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2009-05-19 19:57 UTC (permalink / raw)


Adam Beneschan wrote:
> 
> If your problem is that you're getting a Constraint_Error when the
> subtraction "U16 - 32768" has a negative result, you can convert U16
> to some larger integer type before doing the subtraction:

That wouldn't happen as written because the subtraction would use the base type, 
which is symmetrical (more or less) around zero.

-- 
Jeff Carter
"Pray that there's intelligent life somewhere up in
space, 'cause there's bugger all down here on earth."
Monty Python's Meaning of Life
61



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
  2009-05-19 19:37 ` Adam Beneschan
  2009-05-19 19:55 ` Jeffrey R. Carter
@ 2009-05-19 20:06 ` Ludovic Brenta
  2009-05-19 22:08   ` Olivier Scalbert
  2009-05-20  8:29 ` Stuart
  2009-05-20 11:11 ` Georg Bauhaus
  4 siblings, 1 reply; 15+ messages in thread
From: Ludovic Brenta @ 2009-05-19 20:06 UTC (permalink / raw)


On May 19, 8:51 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
wrote:
> Hello,
>
> My problem:
> I need to convert an "analogic" value which can vary from 0.0 to 1.0
> into a "discrete" value which is a signed 16 bits integer.
>
> My implementation:
> -----------------------------
> with Ada.Text_IO;
>
> procedure convert is
>      type Analog_Value is digits 10 range 0.0 .. 1.0;
>      type Signed_16    is range -32768 .. 32767;
>      type Unsigned_16  is range      0 .. 65535;
>
>      function Cv(Value: Analog_Value) return Signed_16 is
>          U16: Unsigned_16;
>      begin
>          U16 := Unsigned_16(65535.0 * Value);
>          return Signed_16(U16 - 32768);
>      end Cv;
>
>      procedure Put(S16: Signed_16) is
>      begin
>          Ada.Text_IO.Put_Line(Signed_16'image(S16));
>      end put;
> begin
>     Put(Cv(0.00)); -- Must be -32768
>     Put(Cv(0.25)); -- Must be -16384
>     Put(Cv(0.50)); -- Must be      0
>     Put(Cv(0.75)); -- Must be  16383
>     Put(Cv(1.00)); -- Must be  32767
> end convert;
> -----------------------------
>
> My question:
> Is there an other way to do this in Ada (Representation ? Other parts of
> Ada I do not know ?)
>
> My thanks:
> Thank you very much !
> ;-)

Your requirements seem a bit strange to me.  Could you please explaun
why you need the integer to be signed?  Ada has direct support for
fixed-point types (RM 3.5.9).  They would work like this:

0.0            => 2#0000_0000_0000_0000#
0.25           => 2#0100_0000_0000_0000#
0.5            => 2#1000_0000_0000_0000#
0.75           => 2#1100_0000_0000_0000#
1.0-2.0**(-16) => 2#1111_1111_1111_1111#

If you interpret the 16 bits as an unsigned integer, you get

    0
16384
32768
49152
65535

If you interpret these same 16 bits as a signed integer, due to two's
complement you get

 0
 16384
-32768
-16384
-1

Here is my program using this feature:

with Ada.Unchecked_Conversion;
with Interfaces;
with Ada.Text_IO;
procedure Conversion is
   type Analog_Value is delta 2.0 ** (-16) range 0.0 .. 1.0; -- fixed-
point
   for Analog_Value'Size use 16;

   function "+" is
      new Ada.Unchecked_Conversion (Source => Analog_Value,
                                    Target => Interfaces.Integer_16);

   procedure Put (S16 : in Interfaces.Integer_16) is
   begin
      Ada.Text_IO.Put_Line (Interfaces.Integer_16'Image (S16));
   end Put;

begin
   Put (+0.0);
   Put (+0.25);
   Put (+0.5);
   Put (+0.75);
   Put (+(1.0 - Analog_Value'Small));
end Conversion;

I am aware that my program does not address the exact requirement you
expressed but I'm curious to know what the high-level requirement is,
i.e. why you need the conversion in your example.

--
Ludovic Brenta.



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 20:06 ` Ludovic Brenta
@ 2009-05-19 22:08   ` Olivier Scalbert
  0 siblings, 0 replies; 15+ messages in thread
From: Olivier Scalbert @ 2009-05-19 22:08 UTC (permalink / raw)


Ludovic Brenta wrote:
> On May 19, 8:51 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
> wrote:
> Your requirements seem a bit strange to me.  Could you please explaun
> why you need the integer to be signed?  Ada has direct support for
> fixed-point types (RM 3.5.9).  They would work like this:
> 
> 0.0            => 2#0000_0000_0000_0000#
> 0.25           => 2#0100_0000_0000_0000#
> 0.5            => 2#1000_0000_0000_0000#
> 0.75           => 2#1100_0000_0000_0000#
> 1.0-2.0**(-16) => 2#1111_1111_1111_1111#
> 
> If you interpret the 16 bits as an unsigned integer, you get
> 
>     0
> 16384
> 32768
> 49152
> 65535
> 
> If you interpret these same 16 bits as a signed integer, due to two's
> complement you get
> 
>  0
>  16384
> -32768
> -16384
> -1
> 
> Here is my program using this feature:
> 
> with Ada.Unchecked_Conversion;
> with Interfaces;
> with Ada.Text_IO;
> procedure Conversion is
>    type Analog_Value is delta 2.0 ** (-16) range 0.0 .. 1.0; -- fixed-
> point
>    for Analog_Value'Size use 16;
> 
>    function "+" is
>       new Ada.Unchecked_Conversion (Source => Analog_Value,
>                                     Target => Interfaces.Integer_16);
> 
>    procedure Put (S16 : in Interfaces.Integer_16) is
>    begin
>       Ada.Text_IO.Put_Line (Interfaces.Integer_16'Image (S16));
>    end Put;
> 
> begin
>    Put (+0.0);
>    Put (+0.25);
>    Put (+0.5);
>    Put (+0.75);
>    Put (+(1.0 - Analog_Value'Small));
> end Conversion;
> 
> I am aware that my program does not address the exact requirement you
> expressed but I'm curious to know what the high-level requirement is,
> i.e. why you need the conversion in your example.
> 
> --
> Ludovic Brenta.

Hi Ludovic,

The purpose of this conversion is in fact to convert a set of 
Analog_Value, representing an sound wave (normalized to [0.0, 1.0]) to a 
snd (or au) audio sound file. This file format is very simple to manage.
Specs can be found there:
http://www.opengroup.org/public/pubs/external/auformat.html
Inside the specs, you can find:
"All of the linear formats are signed integers, centered at zero."
That is why, I need this strange requirement !

The sound wave is generated by mathematical functions and saved as an 
als file (see a previous post - I do not know how to link to it!).
Then the file is normalized after fetching the min/max and converted 
with the maximum of dynamic to a snd file.

So, no rocket science here!
;-)

Olivier



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 19:57   ` Jeffrey R. Carter
@ 2009-05-19 22:36     ` Adam Beneschan
  0 siblings, 0 replies; 15+ messages in thread
From: Adam Beneschan @ 2009-05-19 22:36 UTC (permalink / raw)


On May 19, 12:57 pm, "Jeffrey R. Carter"
<spam.jrcarter....@nospam.acm.org> wrote:
> Adam Beneschan wrote:
>
> > If your problem is that you're getting a Constraint_Error when the
> > subtraction "U16 - 32768" has a negative result, you can convert U16
> > to some larger integer type before doing the subtraction:
>
> That wouldn't happen as written because the subtraction would use the base type,
> which is symmetrical (more or less) around zero.

Ah, yes---brain freeze on my part.  In that case, I'm with you... the
code originally posted looks just fine to me.

                                  -- Adam



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
                   ` (2 preceding siblings ...)
  2009-05-19 20:06 ` Ludovic Brenta
@ 2009-05-20  8:29 ` Stuart
  2009-05-20  8:48   ` Stuart
  2009-05-20 11:11 ` Georg Bauhaus
  4 siblings, 1 reply; 15+ messages in thread
From: Stuart @ 2009-05-20  8:29 UTC (permalink / raw)


"Olivier Scalbert" <olivier.scalbert@algosyn.com> wrote in message 
news:4a12ffa3$0$2853$ba620e4c@news.skynet.be...
> Hello,
>
> My problem:
> I need to convert an "analogic" value which can vary from 0.0 to 1.0 into 
> a "discrete" value which is a signed 16 bits integer.
>
> My implementation:
> -----------------------------
> with Ada.Text_IO;
>
> procedure convert is
>     type Analog_Value is digits 10 range 0.0 .. 1.0;
>     type Signed_16    is range -32768 .. 32767;
>     type Unsigned_16  is range      0 .. 65535;
>
>     function Cv(Value: Analog_Value) return Signed_16 is
>         U16: Unsigned_16;
>     begin
>         U16 := Unsigned_16(65535.0 * Value);
>         return Signed_16(U16 - 32768);
>     end Cv;
>
>     procedure Put(S16: Signed_16) is
>     begin
>         Ada.Text_IO.Put_Line(Signed_16'image(S16));
>     end put;
> begin
>    Put(Cv(0.00)); -- Must be -32768
>    Put(Cv(0.25)); -- Must be -16384
>    Put(Cv(0.50)); -- Must be      0
>    Put(Cv(0.75)); -- Must be  16383
>    Put(Cv(1.00)); -- Must be  32767
> end convert;
> -----------------------------
>
> My question:
> Is there an other way to do this in Ada (Representation ? Other parts of 
> Ada I do not know ?)

Extending your [reasonable] assumptions about the base type of Analog_Value 
you could dispense with the Unsigned_16 altogether:

   function Cv(Value: Analog_Value) return Signed_16 is
   begin
      return Signed_16(65535.0*Value - 32768.0);
   end Cv;

If you really wanted to you could formally codify the assumptions by 
declaring a working base, then make Analog_Value a subtype of that:

   type Working_Base is digits 10 range -32768.0 .. 65535.0;
   subtype Analog_Value is Working_Base range 0.0 .. 1.0;

Regards
   Stuart





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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20  8:29 ` Stuart
@ 2009-05-20  8:48   ` Stuart
  0 siblings, 0 replies; 15+ messages in thread
From: Stuart @ 2009-05-20  8:48 UTC (permalink / raw)


"Stuart" <stuart@0.0> wrote in message 
news:4a13baef$1_1@glkas0286.greenlnk.net...

> "Olivier Scalbert" <olivier.scalbert@algosyn.com> wrote in message 
> news:4a12ffa3$0$2853$ba620e4c@news.skynet.be...

>> My problem:
>> I need to convert an "analogic" value which can vary from 0.0 to 1.0 into 
>> a "discrete" value which is a signed 16 bits integer.
...
>> with Ada.Text_IO;
>>
>> procedure convert is
>>     type Analog_Value is digits 10 range 0.0 .. 1.0;
>>     type Signed_16    is range -32768 .. 32767;
...
>> begin
...
>>    Put(Cv(0.50)); -- Must be      0
...
>> end convert;


> Extending your [reasonable] assumptions about the base type of 
> Analog_Value you could dispense with the Unsigned_16 altogether:
>
>   function Cv(Value: Analog_Value) return Signed_16 is
>   begin
>      return Signed_16(65535.0*Value - 32768.0);
>   end Cv;

Ooops!

Unfortunately, due to Ada rounding rules this fails your requirement for 
Cv(0.50) as it returns -1.

In my defence I plead that we got very annoyed by the overhead of Ada 
rounding in a similar scenario that we rigged our conversions and don't see 
this problem.  You can might also weedle  your way around the effect of the 
rounding by trying something like:

function Cv(Value: Analog_Value) return Signed_16 is
begin
    return Signed_16(65535.0*Value - 32767.9999);
end Cv;

You could probably _derive_ a value to replace -32768.0 by consideration of 
the rounding effect over the range of inputs 0.0 .. 1.0.

Regards
   Stuart 





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

* Re: Conversion from floating point to signed 16 bits
  2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
                   ` (3 preceding siblings ...)
  2009-05-20  8:29 ` Stuart
@ 2009-05-20 11:11 ` Georg Bauhaus
  2009-05-20 12:06   ` Martin
  4 siblings, 1 reply; 15+ messages in thread
From: Georg Bauhaus @ 2009-05-20 11:11 UTC (permalink / raw)


Olivier Scalbert schrieb:
> Hello,
> 
> My problem:
> I need to convert an "analogic" value which can vary from 0.0 to 1.0
> into a "discrete" value which is a signed 16 bits integer.
> 
> My implementation:
> -----------------------------
> with Ada.Text_IO;
> 
> procedure convert is
>     type Analog_Value is digits 10 range 0.0 .. 1.0;
>     type Signed_16    is range -32768 .. 32767;
>     type Unsigned_16  is range      0 .. 65535;

It might be an idea to use a different name
for Unsigned_16 because this name is also
declared in standard package Interfaces.
Or use qualification. Avoids misunderstandings.



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20 11:11 ` Georg Bauhaus
@ 2009-05-20 12:06   ` Martin
  2009-05-20 15:18     ` Jeffrey R. Carter
  0 siblings, 1 reply; 15+ messages in thread
From: Martin @ 2009-05-20 12:06 UTC (permalink / raw)


On May 20, 12:11 pm, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:
> Olivier Scalbert schrieb:
>
> > Hello,
>
> > My problem:
> > I need to convert an "analogic" value which can vary from 0.0 to 1.0
> > into a "discrete" value which is a signed 16 bits integer.
>
> > My implementation:
> > -----------------------------
> > with Ada.Text_IO;
>
> > procedure convert is
> >     type Analog_Value is digits 10 range 0.0 .. 1.0;
> >     type Signed_16    is range -32768 .. 32767;
> >     type Unsigned_16  is range      0 .. 65535;
>
> It might be an idea to use a different name
> for Unsigned_16 because this name is also
> declared in standard package Interfaces.
> Or use qualification. Avoids misunderstandings.

Or better - just use package Interfaces instead...

Cheers
-- Martin



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20 12:06   ` Martin
@ 2009-05-20 15:18     ` Jeffrey R. Carter
  2009-05-20 15:23       ` Martin
  0 siblings, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2009-05-20 15:18 UTC (permalink / raw)


Martin wrote:
> 
> Or better - just use package Interfaces instead...

No. Interfaces.Unsigned_16 is a modular type. The OP's Unsigned_16 is a signed 
integer type.

-- 
Jeff Carter
"English bed-wetting types."
Monty Python & the Holy Grail
15



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20 15:18     ` Jeffrey R. Carter
@ 2009-05-20 15:23       ` Martin
  2009-05-20 15:47         ` Adam Beneschan
  0 siblings, 1 reply; 15+ messages in thread
From: Martin @ 2009-05-20 15:23 UTC (permalink / raw)


On May 20, 4:18 pm, "Jeffrey R. Carter"
<spam.jrcarter....@nospam.acm.org> wrote:
> Martin wrote:
>
> > Or better - just use package Interfaces instead...
>
> No. Interfaces.Unsigned_16 is a modular type. The OP's Unsigned_16 is a signed
> integer type.
>
> --
> Jeff Carter
> "English bed-wetting types."
> Monty Python & the Holy Grail
> 15

So it is!!

A rather poorly named type then...tricky to think of a better name
though - perhaps the Interfaces names should have been Modular_16 /
etc. Too late now...back to Int16 and Uint16 it is then...

Cheers
-- Martin



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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20 15:23       ` Martin
@ 2009-05-20 15:47         ` Adam Beneschan
  2009-05-20 16:13           ` Martin
  0 siblings, 1 reply; 15+ messages in thread
From: Adam Beneschan @ 2009-05-20 15:47 UTC (permalink / raw)


On May 20, 8:23 am, Martin <martin.do...@btopenworld.com> wrote:
> On May 20, 4:18 pm, "Jeffrey R. Carter"
>
> <spam.jrcarter....@nospam.acm.org> wrote:
> > Martin wrote:
>
> > > Or better - just use package Interfaces instead...
>
> > No. Interfaces.Unsigned_16 is a modular type. The OP's Unsigned_16 is a signed
> > integer type.
>
> > --
> > Jeff Carter
> > "English bed-wetting types."
> > Monty Python & the Holy Grail
> > 15
>
> So it is!!
>
> A rather poorly named type then...tricky to think of a better name
> though - perhaps the Interfaces names should have been Modular_16 /
> etc. Too late now...back to Int16 and Uint16 it is then...

As Jeff said, the OP's Unsigned_16 is a "signed integer type"
according to the definitions in the Ada standard, which defines two
kinds of integer types, "signed" and "modular".  There is no
"unsigned" integer type.  However, a type like Unsigned_16 will
usually be implemented (on an 8-bit-byte-addressable machine) as a 16-
bit unsigned integer (objects of the type will occupy exactly two
bytes, and the code will use instructions that operate on 16-bit
unsigned integers where possible, if such instructions exist).  To me,
that makes it hard to criticize the choice of name---practically
speaking, it's an unsigned 16-bit integer type in normal industry
parlance, and we can't expect Ada programmers to know the details of
the standard's terminology as well as we language lawyers do.  As for
the complaint that the type name be confused with types in
Interfaces---maybe, maybe not.  It depends on who'll be reading the
code.  I don't think we can decree that every name defined by the
Standard is off-limits for programming use, so we have to draw a line
somewhere.

                                   -- Adam





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

* Re: Conversion from floating point to signed 16 bits
  2009-05-20 15:47         ` Adam Beneschan
@ 2009-05-20 16:13           ` Martin
  0 siblings, 0 replies; 15+ messages in thread
From: Martin @ 2009-05-20 16:13 UTC (permalink / raw)


On May 20, 4:47 pm, Adam Beneschan <a...@irvine.com> wrote:
> On May 20, 8:23 am, Martin <martin.do...@btopenworld.com> wrote:
>
>
>
> > On May 20, 4:18 pm, "Jeffrey R. Carter"
>
> > <spam.jrcarter....@nospam.acm.org> wrote:
> > > Martin wrote:
>
> > > > Or better - just use package Interfaces instead...
>
> > > No. Interfaces.Unsigned_16 is a modular type. The OP's Unsigned_16 is a signed
> > > integer type.
>
> > > --
> > > Jeff Carter
> > > "English bed-wetting types."
> > > Monty Python & the Holy Grail
> > > 15
>
> > So it is!!
>
> > A rather poorly named type then...tricky to think of a better name
> > though - perhaps the Interfaces names should have been Modular_16 /
> > etc. Too late now...back to Int16 and Uint16 it is then...
>
> As Jeff said, the OP's Unsigned_16 is a "signed integer type"
> according to the definitions in the Ada standard, which defines two
> kinds of integer types, "signed" and "modular".  There is no
> "unsigned" integer type.  However, a type like Unsigned_16 will
> usually be implemented (on an 8-bit-byte-addressable machine) as a 16-
> bit unsigned integer (objects of the type will occupy exactly two
> bytes, and the code will use instructions that operate on 16-bit
> unsigned integers where possible, if such instructions exist).  To me,
> that makes it hard to criticize the choice of name---practically
> speaking, it's an unsigned 16-bit integer type in normal industry
> parlance, and we can't expect Ada programmers to know the details of
> the standard's terminology as well as we language lawyers do.  As for
> the complaint that the type name be confused with types in
> Interfaces---maybe, maybe not.  It depends on who'll be reading the
> code.  I don't think we can decree that every name defined by the
> Standard is off-limits for programming use, so we have to draw a line
> somewhere.
>
>                                    -- Adam

Yes, the names in Interfaces do match those used by the C-style of
languages but it's a shame that because those other languages don't
have the rich variety that Ada does that we end up with a bit of a
mismatch.

I'm so used to Unsigned_16/etc being modular that whenever I see them
that's what I expect.

Cheers
-- Martin



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

end of thread, other threads:[~2009-05-20 16:13 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-19 18:51 Conversion from floating point to signed 16 bits Olivier Scalbert
2009-05-19 19:37 ` Adam Beneschan
2009-05-19 19:57   ` Jeffrey R. Carter
2009-05-19 22:36     ` Adam Beneschan
2009-05-19 19:55 ` Jeffrey R. Carter
2009-05-19 20:06 ` Ludovic Brenta
2009-05-19 22:08   ` Olivier Scalbert
2009-05-20  8:29 ` Stuart
2009-05-20  8:48   ` Stuart
2009-05-20 11:11 ` Georg Bauhaus
2009-05-20 12:06   ` Martin
2009-05-20 15:18     ` Jeffrey R. Carter
2009-05-20 15:23       ` Martin
2009-05-20 15:47         ` Adam Beneschan
2009-05-20 16:13           ` Martin

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