digitalmars.D - Wanted: 128 bit integers
- Paul D. Anderson (21/21) Mar 13 2012 I'm working on a decimal arithmetic project and I need 128 bit
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (5/24) Mar 13 2012 The D language specifies 128-bit integers: cent and ucent. They just
- Manu (4/34) Mar 14 2012 Why aren't they implemented in a library for the time being at least, so
- Daniel Murphy (7/9) Mar 14 2012 The obvious answer is because nobody's done it yet.
- Andrei Alexandrescu (5/16) Mar 15 2012 My suggestion is to focus on fixed arbitrary-sized integers in Phobos,
- bearophile (8/11) Mar 15 2012 I think library-defined fixed arbitrary-sized integers and
- Daniel Murphy (4/8) Mar 15 2012 Yeah. A lot of the BigInt code can probably be adapted, if someone want...
- Paul D. Anderson (7/21) Mar 15 2012 I was really only checking to see if anyone had already
- Jonathan M Davis (8/15) Mar 14 2012 I believe that what it really comes down to is that cent and ucent were ...
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (9/24) Mar 14 2012 There aren't really any platforms that natively support 128-bit
- Jonathan M Davis (5/33) Mar 14 2012 long long is 128 bits on 64-bit Linux. That's what I meant by support. 3...
- Daniel Murphy (3/4) Mar 14 2012 Are you sure about this? I think we already had this discussion...
- James Miller (5/11) Mar 14 2012 Same discussion, different topic. I think the one before was sparked
- Jonathan M Davis (4/10) Mar 14 2012 If it isn't, then whatever that discussion was obviously didn't stick in...
- Daniel Murphy (6/17) Mar 14 2012 long double (aka real, a much better name) is 128 bits (including paddin...
- bearophile (5/9) Mar 14 2012 You are able to support 128 bit numbers even on a 16 bit system
I'm working on a decimal arithmetic project and I need 128 bit integers in order to implement the decimal128 type. (The decimal value is stored in 128 bits; the coefficient field is 114 bits, to hold values with 34 decimal digits.) I could use BigInt (but that's overkill) or I could code them up myself, which I'm willing to do if no alternative exists. But surely someone has already created this type, either as part of a larger project or as some kind of test problem, etc. Or perhaps someone would like to tackle it as a project of their own. I specifically need unsigned 128 bit integers, but both signed and unsigned versions would probably have more general applications. Better yet, if it checked for overflow, like Andrei's CheckedInt class in TDPL, it would be more immediately useful. This could also be the basis for a general fixed-size integer type, where the size is specified: CheckedInt!128, CheckedInt!96, etc. I recall having seen something like this mentioned in this forum. So has anyone already done this? Does anyone want to take it on? Thanks, Paul
Mar 13 2012
On 14-03-2012 01:34, Paul D. Anderson wrote:I'm working on a decimal arithmetic project and I need 128 bit integers in order to implement the decimal128 type. (The decimal value is stored in 128 bits; the coefficient field is 114 bits, to hold values with 34 decimal digits.) I could use BigInt (but that's overkill) or I could code them up myself, which I'm willing to do if no alternative exists. But surely someone has already created this type, either as part of a larger project or as some kind of test problem, etc. Or perhaps someone would like to tackle it as a project of their own. I specifically need unsigned 128 bit integers, but both signed and unsigned versions would probably have more general applications. Better yet, if it checked for overflow, like Andrei's CheckedInt class in TDPL, it would be more immediately useful. This could also be the basis for a general fixed-size integer type, where the size is specified: CheckedInt!128, CheckedInt!96, etc. I recall having seen something like this mentioned in this forum. So has anyone already done this? Does anyone want to take it on? Thanks, PaulThe D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet... -- - Alex
Mar 13 2012
On 14 March 2012 02:37, Alex R=C3=B8nne Petersen <xtzgzorex gmail.com> wrot= e:On 14-03-2012 01:34, Paul D. Anderson wrote:Why aren't they implemented in a library for the time being at least, so code can compile and work?I'm working on a decimal arithmetic project and I need 128 bit integers in order to implement the decimal128 type. (The decimal value is stored in 128 bits; the coefficient field is 114 bits, to hold values with 34 decimal digits.) I could use BigInt (but that's overkill) or I could code them up myself, which I'm willing to do if no alternative exists. But surely someone has already created this type, either as part of a larger project or as some kind of test problem, etc. Or perhaps someone would like to tackle it as a project of their own. I specifically need unsigned 128 bit integers, but both signed and unsigned versions would probably have more general applications. Better yet, if it checked for overflow, like Andrei's CheckedInt class in TDPL, it would be more immediately useful. This could also be the basis for a general fixed-size integer type, where the size is specified: CheckedInt!128, CheckedInt!96, etc. I recall having seen something like this mentioned in this forum. So has anyone already done this? Does anyone want to take it on? Thanks, PaulThe D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet...
Mar 14 2012
"Manu" <turkeyman gmail.com> wrote in message news:mailman.657.1331715447.4860.digitalmars-d puremagic.com...Why aren't they implemented in a library for the time being at least, so code can compile and work?The obvious answer is because nobody's done it yet. I have a branch that partially implements ucent in the dmd backend (somewhere in my fork on github), but it will likely be at least a month before I have time to work on it again. It looks like it will be pretty easy on 64 bit.
Mar 14 2012
On 3/15/12 1:42 AM, Daniel Murphy wrote:"Manu"<turkeyman gmail.com> wrote in message news:mailman.657.1331715447.4860.digitalmars-d puremagic.com...My suggestion is to focus on fixed arbitrary-sized integers in Phobos, and then add optimizations for 64-bit integers on architectures that support it. AndreiWhy aren't they implemented in a library for the time being at least, so code can compile and work?The obvious answer is because nobody's done it yet. I have a branch that partially implements ucent in the dmd backend (somewhere in my fork on github), but it will likely be at least a month before I have time to work on it again. It looks like it will be pretty easy on 64 bit.
Mar 15 2012
Andrei Alexandrescu:My suggestion is to focus on fixed arbitrary-sized integers in Phobos, and then add optimizations for 64-bit integers on architectures that support it.I think library-defined fixed arbitrary-sized integers and built-in cent/ucent types are both useful to have. One doesn't fully replace the other. cent/ucent is more efficient (even on 32 bit systems), while FixedInt is more flexible. But both are low-priority. Bye, bearophile
Mar 15 2012
"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:jjt1lh$pfb$1 digitalmars.com...My suggestion is to focus on fixed arbitrary-sized integers in Phobos, and then add optimizations for 64-bit integers on architectures that support it. AndreiYeah. A lot of the BigInt code can probably be adapted, if someone wants to give it a go.
Mar 15 2012
On Thursday, 15 March 2012 at 15:39:47 UTC, Daniel Murphy wrote:"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:jjt1lh$pfb$1 digitalmars.com...I was really only checking to see if anyone had already implemented 128-bit integers. It seems like the answer is no, but Daniel may have some code. It looks like the quickest solution is for me to do it myself. I'll let you all know when it's ready. PaulMy suggestion is to focus on fixed arbitrary-sized integers in Phobos, and then add optimizations for 64-bit integers on architectures that support it. AndreiYeah. A lot of the BigInt code can probably be adapted, if someone wants to give it a go.
Mar 15 2012
On Wednesday, March 14, 2012 10:57:03 Manu wrote:On 14 March 2012 02:37, Alex Rønne Petersen <xtzgzorex gmail.com> wrote:I believe that what it really comes down to is that cent and ucent were set aside just in case they would be needed with no specific plans to do anything with them. So, they'll probably be implemented eventually, but they're definitely not a priority. And if you really need larger integers, then there's BigInt. Prior to the 64-bit ports of dmd (which are fairly recent), dmd wasn't even on any architectures that supported 128 bit integers anyway. - Jonathan M DavisOn 14-03-2012 01:34, Paul D. Anderson wrote: The D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet...Why aren't they implemented in a library for the time being at least, so code can compile and work?
Mar 14 2012
On 14-03-2012 17:49, Jonathan M Davis wrote:On Wednesday, March 14, 2012 10:57:03 Manu wrote:There aren't really any platforms that natively support 128-bit integers, even today. The most "support" you'll get is SIMD-like extensions, but those aren't necessarily useful for implementing 128-bit integers. So, most likely, the compiler would just have to unroll 128-bit operations just as it does for 64-bit operations on 32-bit targets. -- - AlexOn 14 March 2012 02:37, Alex Rønne Petersen<xtzgzorex gmail.com> wrote:I believe that what it really comes down to is that cent and ucent were set aside just in case they would be needed with no specific plans to do anything with them. So, they'll probably be implemented eventually, but they're definitely not a priority. And if you really need larger integers, then there's BigInt. Prior to the 64-bit ports of dmd (which are fairly recent), dmd wasn't even on any architectures that supported 128 bit integers anyway. - Jonathan M DavisOn 14-03-2012 01:34, Paul D. Anderson wrote: The D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet...Why aren't they implemented in a library for the time being at least, so code can compile and work?
Mar 14 2012
On Wednesday, March 14, 2012 17:51:49 Alex Rønne Petersen wrote:On 14-03-2012 17:49, Jonathan M Davis wrote:long long is 128 bits on 64-bit Linux. That's what I meant by support. 32-bit doesn't have that with any C type on any platform that I know of. I have no idea how it's implemented though. - Jonathan M DavisOn Wednesday, March 14, 2012 10:57:03 Manu wrote:There aren't really any platforms that natively support 128-bit integers, even today. The most "support" you'll get is SIMD-like extensions, but those aren't necessarily useful for implementing 128-bit integers. So, most likely, the compiler would just have to unroll 128-bit operations just as it does for 64-bit operations on 32-bit targets.On 14 March 2012 02:37, Alex Rønne Petersen<xtzgzorex gmail.com> wrote:I believe that what it really comes down to is that cent and ucent were set aside just in case they would be needed with no specific plans to do anything with them. So, they'll probably be implemented eventually, but they're definitely not a priority. And if you really need larger integers, then there's BigInt. Prior to the 64-bit ports of dmd (which are fairly recent), dmd wasn't even on any architectures that supported 128 bit integers anyway. - Jonathan M DavisOn 14-03-2012 01:34, Paul D. Anderson wrote: The D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet...Why aren't they implemented in a library for the time being at least, so code can compile and work?
Mar 14 2012
"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.666.1331749219.4860.digitalmars-d puremagic.com...long long is 128 bits on 64-bit Linux.Are you sure about this? I think we already had this discussion...
Mar 14 2012
On 15 March 2012 13:55, Daniel Murphy <yebblies nospamgmail.com> wrote:"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.666.1331749219.4860.digitalmars-d puremagic.com...Same discussion, different topic. I think the one before was sparked by size_t issues. -- James Millerlong long is 128 bits on 64-bit Linux.Are you sure about this? =C2=A0I think we already had this discussion...
Mar 14 2012
On Thursday, March 15, 2012 11:55:46 Daniel Murphy wrote:"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.666.1331749219.4860.digitalmars-d puremagic.com...If it isn't, then whatever that discussion was obviously didn't stick in my head. - Jonathan M Davislong long is 128 bits on 64-bit Linux.Are you sure about this? I think we already had this discussion...
Mar 14 2012
"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.685.1331774722.4860.digitalmars-d puremagic.com...On Thursday, March 15, 2012 11:55:46 Daniel Murphy wrote:long double (aka real, a much better name) is 128 bits (including padding) on some platforms/compilers, I'm pretty sure long long is 64 bits in every x86-64 memory model. Some compilers do however support 128 bit integer types on some platforms."Jonathan M Davis" <jmdavisProg gmx.com> wrote in message news:mailman.666.1331749219.4860.digitalmars-d puremagic.com...If it isn't, then whatever that discussion was obviously didn't stick in my head. - Jonathan M Davislong long is 128 bits on 64-bit Linux.Are you sure about this? I think we already had this discussion...
Mar 14 2012
Jonathan M Davis:Prior to the 64-bit ports of dmd (which are fairly recent), dmd wasn't even on any architectures that supported 128 bit integers anyway.You are able to support 128 bit numbers even on a 16 bit system :-) Bye, bearophile
Mar 14 2012