comp.lang.ada
 help / color / mirror / Atom feed
* Feature or Bug?  2#1111# shifted by 4 is 224
@ 2008-06-02 15:17 Dennis Hoppe
  2008-06-02 16:11 ` Tero Koskinen
  2008-06-02 22:32 ` Gautier
  0 siblings, 2 replies; 13+ messages in thread
From: Dennis Hoppe @ 2008-06-02 15:17 UTC (permalink / raw)


Hi,

we probably found a bug in Ada or we cannot realize, that this is indeed 
a feature ;)

In Example A, we defined a simple modular shift to the left by means of 
Item * 2**N. N is defined as an Integer. This example works well and 
Shift_Left(2#1111#, 4) returns 0.

-- Example A
type Modular_Type is mod 2**4;
function Shift_Left (Item : in Modular_Type;
                      N    : in Integer) return Modular_Type is
begin
   return Item * 2**N;
end Shift_Left;


In Example B, we limit the parameter N to Positive, because we do not 
want "negative" shifts. The result of Shift_Left(2#1111#, 4) is 224
(2#11100000#) !

-- Example B
type Modular_Type is mod 2**4;
function Shift_Left (Item : in Modular_Type;
                      N    : in Positive) return Modular_Type is
begin
   return Item * 2**N;
end Shift_Left;



Why does this happen? Positive is defined as all Integer values starting 
at 1 through the highest value of Integer, so the result should also be 
0. Especially, because the returning value is additionally limited by 
mod 2**4.

Thanks,
   Dennis Hoppe



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

end of thread, other threads:[~2008-06-04  3:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-02 15:17 Feature or Bug? 2#1111# shifted by 4 is 224 Dennis Hoppe
2008-06-02 16:11 ` Tero Koskinen
2008-06-02 17:59   ` Ludovic Brenta
2008-06-02 18:52     ` Dennis Hoppe
2008-06-03  0:51       ` Jeffrey R. Carter
2008-06-03  4:26         ` Gautier
2008-06-03 19:36           ` Jeffrey R. Carter
2008-06-03 17:56         ` Adam Beneschan
2008-06-03 19:39           ` Jeffrey R. Carter
2008-06-03  8:10       ` Ludovic Brenta
2008-06-03 12:59       ` Samuel Tardieu
2008-06-04  3:36     ` Tero Koskinen
2008-06-02 22:32 ` Gautier

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