Prev: 100% without investment online part time jobs..(adsense,datawork,neobux..more jobs)
Next: installing SPARK GPL on Windows
From: Robert A Duff on 8 Aug 2010 18:22 "(see below)" <yaldnif.w(a)blueyonder.co.uk> writes: > I don't use non-power-of-2 mod types, but I write emulators, and I would be > stuffed if I could not declare, e.g.: > > type KDF9_word is mod 2**48; Yes, that's one of the few cases where modular types make sense. Unfortunately, nothing in the Ada RM requires implementations to accept that. GNAT does, on all targets. But for a circular buffer of (say) 100 items? No, I wouldn't use modular types for the index. - Bob
From: tmoran on 8 Aug 2010 18:35 > And it would be desirable, because in most cases the explicit > "mod" (or "%") is more readable. I := Ring_Indices'succ(I); vs I := (I + 1) mod Ring_Size; or Bearing := Bearing + Turn_Angle; vs Bearing := (Bearing + Turn_Angle) mod 360;
From: Yannick Duchêne (Hibou57) on 9 Aug 2010 00:46 Le Sun, 08 Aug 2010 22:51:37 +0200, Robert A Duff <bobduff(a)shell01.theworld.com> a écrit: > The only feature > that's worse than "modular types" is "modular types with a > non-power-of-2 modulus". ;-) Illegal in SPARK (not that I support the idea that non power of 2 modular types are ugly beast)
From: J-P. Rosen on 9 Aug 2010 01:52 Robert A Duff a �crit : > P.S. Can anybody recall the definition of "not" on modular > types, when the modulus is not a power of 2, without > looking it up? Sure. Like any other operation. First you do the operation in the mathematical sense, then you take the mathematical result mod T'Modulus. > Hint: It makes no sense. It makes sense because it is consistent with all other operations on modular types. Whether it is usefule is another story ;-) > The only feature > that's worse than "modular types" is "modular types with a > non-power-of-2 modulus". ;-) Hmmm... Hash coded tables? -- --------------------------------------------------------- J-P. Rosen (rosen(a)adalog.fr) Visit Adalog's web site at http://www.adalog.fr
From: Robert A Duff on 9 Aug 2010 09:28
"J-P. Rosen" <rosen(a)adalog.fr> writes: > Robert A Duff a �crit : >> P.S. Can anybody recall the definition of "not" on modular >> types, when the modulus is not a power of 2, without >> looking it up? > Sure. Like any other operation. First you do the operation in the > mathematical sense, then you take the mathematical result mod T'Modulus. "and", "or", and "xor" are defined that way (bit-wise logical operation, followed by "mod"). "not" is NOT defined as bit-wise "not" followed by "mod". type T is mod 3; X : T := 2; ... X := not X; Now X = 0. 2 = 2#10#. Bit-wise "not" of that is 2#01#. "mod" that by 3, and you get 2#1#. >> Hint: It makes no sense. > It makes sense because it is consistent with all other operations on > modular types. Whether it is usefule is another story ;-) It is neither consistent nor useful. I'll stick with "makes no sense". >> The only feature >> that's worse than "modular types" is "modular types with a >> non-power-of-2 modulus". ;-) > Hmmm... Hash coded tables? Signed integers work fine for that. Except when you need that one extra bit -- that's the problem. - Bob |