Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 14, 2012 Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
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 |
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul D. Anderson | 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, > > Paul > The D language specifies 128-bit integers: cent and ucent. They just aren't implemented yet... -- - Alex |
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen Attachments:
| On 14 March 2012 02:37, Alex Rønne Petersen <xtzgzorex@gmail.com> wrote:
> 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,
>>
>> Paul
>>
>>
> 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?
|
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
On Wednesday, March 14, 2012 10:57:03 Manu wrote:
> On 14 March 2012 02:37, Alex Rønne Petersen <xtzgzorex@gmail.com> wrote:
> > On 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?
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 Davis
|
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 14-03-2012 17:49, Jonathan M Davis wrote: > On Wednesday, March 14, 2012 10:57:03 Manu wrote: >> On 14 March 2012 02:37, Alex Rønne Petersen<xtzgzorex@gmail.com> wrote: >>> On 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? > > 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 Davis 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. -- - Alex |
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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
|
March 14, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On Wednesday, March 14, 2012 17:51:49 Alex Rønne Petersen wrote:
> On 14-03-2012 17:49, Jonathan M Davis wrote:
> > On Wednesday, March 14, 2012 10:57:03 Manu wrote:
> >> On 14 March 2012 02:37, Alex Rønne Petersen<xtzgzorex@gmail.com> wrote:
> >>> On 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?
> >
> > 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 Davis
>
> 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.
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 Davis
|
March 15, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | "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... |
March 15, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | 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...
>>
>> long long is 128 bits on 64-bit Linux.
>>
>
> Are you sure about this? I think we already had this discussion...
>
>
Same discussion, different topic. I think the one before was sparked by size_t issues.
--
James Miller
|
March 15, 2012 Re: Wanted: 128 bit integers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | 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...
>
> > long long is 128 bits on 64-bit Linux.
>
> Are you sure about this? I think we already had this discussion...
If it isn't, then whatever that discussion was obviously didn't stick in my head.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation