www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is there a good lib out there to handle large integer of know size ?

reply deadalnix <deadalnix gmail.com> writes:
In my case, I'm interested in 160 and 256 bits integers. Using 
BigInt seems wasteful as I know the integer size I want. Do we 
have something like this around ?
Jan 06
next sibling parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 09:25:45PM +0000, deadalnix via Digitalmars-d wrote:
 In my case, I'm interested in 160 and 256 bits integers. Using BigInt
 seems wasteful as I know the integer size I want. Do we have something
 like this around ?
If not, it may be something nice to add to Phobos. Integer width can be passed as a compile-time parameter, making it completely generic. T -- Right now I'm having amnesia and deja vu at the same time. I think I've forgotten this before.
Jan 06
prev sibling parent reply Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
 In my case, I'm interested in 160 and 256 bits integers. Using 
 BigInt seems wasteful as I know the integer size I want. Do we 
 have something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
Jan 06
next sibling parent reply deadalnix <deadalnix gmail.com> writes:
On Wednesday, 6 January 2016 at 21:57:13 UTC, Guillaume Piolat 
wrote:
 On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
 In my case, I'm interested in 160 and 256 bits integers. Using 
 BigInt seems wasteful as I know the integer size I want. Do we 
 have something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
That is awesome ! Won't do the 160 bits case, but I can deal with that. Did you consider this as a worthy addition to phobos ? I think it is.
Jan 06
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/6/16 5:18 PM, deadalnix wrote:
 On Wednesday, 6 January 2016 at 21:57:13 UTC, Guillaume Piolat wrote:
 On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
 In my case, I'm interested in 160 and 256 bits integers. Using BigInt
 seems wasteful as I know the integer size I want. Do we have
 something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
That is awesome ! Won't do the 160 bits case, but I can deal with that. Did you consider this as a worthy addition to phobos ? I think it is.
Yes, we need to add that to phobos. Who could be the champion? -- Andrei
Jan 06
next sibling parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 05:23:12PM -0500, Andrei Alexandrescu via Digitalmars-d
wrote:
 On 1/6/16 5:18 PM, deadalnix wrote:
On Wednesday, 6 January 2016 at 21:57:13 UTC, Guillaume Piolat wrote:
On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
In my case, I'm interested in 160 and 256 bits integers. Using
BigInt seems wasteful as I know the integer size I want. Do we have
something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
That is awesome ! Won't do the 160 bits case, but I can deal with that. Did you consider this as a worthy addition to phobos ? I think it is.
Yes, we need to add that to phobos. Who could be the champion? --
Here are a few things that should probably be addressed before merging to Phobos: - Better error message when user attempts to instantiate a wide int with non-power-of-2 bits. (Currently spews a whole bunch of internal compile errors.) - toString() needs to: 1) Be the non-allocating overload: void toString(scope void delegate(const(char)[]) dg) {...} 2) Output in decimal by default instead of hex. - Need a nice way of initializing wide ints from literals. - [optional] Division performance can probably be improved. T -- I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller
Jan 06
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 01/06/2016 05:47 PM, H. S. Teoh via Digitalmars-d wrote:
 On Wed, Jan 06, 2016 at 05:23:12PM -0500, Andrei Alexandrescu via
Digitalmars-d wrote:
 On 1/6/16 5:18 PM, deadalnix wrote:
 On Wednesday, 6 January 2016 at 21:57:13 UTC, Guillaume Piolat wrote:
 On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
 In my case, I'm interested in 160 and 256 bits integers. Using
 BigInt seems wasteful as I know the integer size I want. Do we have
 something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
That is awesome ! Won't do the 160 bits case, but I can deal with that. Did you consider this as a worthy addition to phobos ? I think it is.
Yes, we need to add that to phobos. Who could be the champion? --
Here are a few things that should probably be addressed before merging to Phobos: - Better error message when user attempts to instantiate a wide int with non-power-of-2 bits. (Currently spews a whole bunch of internal compile errors.) - toString() needs to: 1) Be the non-allocating overload: void toString(scope void delegate(const(char)[]) dg) {...} 2) Output in decimal by default instead of hex. - Need a nice way of initializing wide ints from literals. - [optional] Division performance can probably be improved.
This is a good list, and not difficult to implement. Thanks! -- Andrei
Jan 06
prev sibling next sibling parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 02:47:24PM -0800, H. S. Teoh via Digitalmars-d wrote:
[...]
 - Better error message when user attempts to instantiate a wide int with
   non-power-of-2 bits. (Currently spews a whole bunch of internal
   compile errors.)
[...] https://github.com/d-gamedev-team/gfm/pull/143 T -- Ph.D. = Permanent head Damage
Jan 08
prev sibling next sibling parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 02:47:24PM -0800, H. S. Teoh via Digitalmars-d wrote:
[...]
 - Need a nice way of initializing wide ints from literals.
[...] https://github.com/d-gamedev-team/gfm/pull/144 T -- Try to keep an open mind, but not so open your brain falls out. -- theboz
Jan 08
prev sibling parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 02:47:24PM -0800, H. S. Teoh via Digitalmars-d wrote:
[...]
 - toString() needs to:
   1) Be the non-allocating overload:
 
   	void toString(scope void delegate(const(char)[]) dg) {...}
 
   2) Output in decimal by default instead of hex.
[...] https://github.com/d-gamedev-team/gfm/pull/145 T -- Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Jan 08
parent reply rumbu <rumbu rumbu.ro> writes:
Here is what I've done as a side project for a decimal data type:

https://github.com/rumbu13/fixed/blob/master/src/fixedtest/fixed.d

- signed and unsigned fixed width types;
- all current operators supported (even signed shift or power);
- optimized division and multiplication;
- formatting with specifiers;
- conversion (currently 16 and 10-based numbers)
- casting;
- endianess aware;
- minimal dependendencies; (std.traits, std.format - needed for 
FormatSpec).

Working on:
- floating point conversion optimization;
- random base conversion;
- rangify current strings conversions;
- some bugs for the signed data type;
Jan 09
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/9/16 6:31 AM, rumbu wrote:
 Here is what I've done as a side project for a decimal data type:

 https://github.com/rumbu13/fixed/blob/master/src/fixedtest/fixed.d
Who can champion ONE fixed large integer library for Phobos? -- Andrei
Jan 09
prev sibling next sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 6 January 2016 at 22:18:48 UTC, deadalnix wrote:
 On Wednesday, 6 January 2016 at 21:57:13 UTC, Guillaume Piolat 
 wrote:
 On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
 In my case, I'm interested in 160 and 256 bits integers. 
 Using BigInt seems wasteful as I know the integer size I 
 want. Do we have something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
That is awesome ! Won't do the 160 bits case, but I can deal with that. Did you consider this as a worthy addition to phobos ? I think it is.
Well I've never ever used them after writing. Perhaps should be in their own dub package. Need wideint literals at a minimum!
Jan 06
prev sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 6 January 2016 at 22:18:48 UTC, deadalnix wrote:
 Won't do the 160 bits case
Now that I think of it, wideint could be used as a base for fixed point and 160 bit integers, much like unsigned BigInt is implemented with signed BigInt (or perhaps it's the other way around). I've tried with https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/fixedpoint.d but it's limited.
Jan 06
prev sibling parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Wed, Jan 06, 2016 at 09:57:13PM +0000, Guillaume Piolat via Digitalmars-d
wrote:
 On Wednesday, 6 January 2016 at 21:25:45 UTC, deadalnix wrote:
In my case, I'm interested in 160 and 256 bits integers. Using BigInt
seems wasteful as I know the integer size I want. Do we have
something like this around ?
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/wideint.d public domain. Slow division. Only power-of-2 bits supported.
Looks nice. With a bit of work, it could be a potential Phobos addition IMO. T -- Perhaps the most widespread illusion is that if we were in power we would behave very differently from those who now hold it---when, in truth, in order to get power we would have to become very much like them. -- Unknown
Jan 06