digitalmars.D.learn - Ada-Style Modulo Integer Types
- =?UTF-8?B?Tm9yZGzDtnc=?= (15/15) Apr 22 2016 Have anybody implement Ada-style modulo types
- =?UTF-8?B?Tm9yZGzDtnc=?= (7/9) Apr 22 2016 Here's my first try
- Timon Gehr (12/22) Apr 22 2016 Why do you want to perform a range check? Shouldn't it just take the
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/9) Jul 20 2020 Now at
- Ivan Kazmenko (16/18) Apr 22 2016 I've implemented a proof-of-concept for algorithmic programming
Have anybody implement Ada-style modulo types https://en.wikibooks.org/wiki/Ada_Programming/Types/mod in D? I'm thinking modulo.d: struct Mod(size_t m, Block = uint) { static assert(m <= 2^^(8*Block.sizeof)); Block value; } typically used as Mod!(8, ubyte) Mod!(256, ubyte) Mod!(8, uint) ?
Apr 22 2016
On Friday, 22 April 2016 at 17:37:44 UTC, Nordlöw wrote:Have anybody implement Ada-style modulo types https://en.wikibooks.org/wiki/Ada_Programming/Types/modHere's my first try https://github.com/nordlow/phobos-next/blob/master/src/modulo.d Is there a way to use alias _value this; except mutation of _value which should check that _value is within value range (0 .. m-1)?
Apr 22 2016
On 22.04.2016 21:52, Nordlöw wrote:On Friday, 22 April 2016 at 17:37:44 UTC, Nordlöw wrote:Why do you want to perform a range check? Shouldn't it just take the appropriate remainder? Anyway, the following will do what you request: struct Mod(int M){ private int x; property int prop(int x)in{assert(0<=x&&x<M);}body{ return this.x=x; } property int prop(){ return x; } alias prop this; }Have anybody implement Ada-style modulo types https://en.wikibooks.org/wiki/Ada_Programming/Types/modHere's my first try https://github.com/nordlow/phobos-next/blob/master/src/modulo.d Is there a way to use alias _value this; except mutation of _value which should check that _value is within value range (0 .. m-1)?
Apr 22 2016
On Friday, 22 April 2016 at 19:52:46 UTC, Nordlöw wrote:On Friday, 22 April 2016 at 17:37:44 UTC, Nordlöw wrote:Now at https://github.com/nordlow/phobos-next/blob/69e57fb2eed57d7450d746baa30d9f112d76f527/src/nxt/modulo.dHave anybody implement Ada-style modulo types https://en.wikibooks.org/wiki/Ada_Programming/Types/modHere's my first try https://github.com/nordlow/phobos-next/blob/master/src/modulo.d
Jul 20 2020
On Friday, 22 April 2016 at 17:37:44 UTC, Nordlöw wrote:Have anybody implement Ada-style modulo types https://en.wikibooks.org/wiki/Ada_Programming/Types/modI've implemented a proof-of-concept for algorithmic programming competitions [1]. In these competitions, quite a few problems ask to calculate the result modulo some large prime number. The usual idea is that, this way, you still have to solve the underlying algorithmic problem, but the magnitude of calculated values does not affect your algorithmic complexity. Disclaimer: it is incomplete and tuned for the competitions, and thus not ready for general use. For the record, there is also an implementation of modulo integer for the same problem in C++ by Vladislav Isenbaev. Note that the solutions themselves are not the same, so the timing can't be compared directly. Ivan Kazmenko. [1] http://codeforces.com/contest/628/submission/16212299 [2] http://codeforces.com/contest/628/submission/16610362
Apr 22 2016