Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #4635 > unrolled thread
| Started by | cps <chrissusie8@gmail.com> |
|---|---|
| First post | 2011-05-03 13:39 -0700 |
| Last post | 2011-05-06 08:00 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.c++
literals for an int128 class cps <chrissusie8@gmail.com> - 2011-05-03 13:39 -0700
Re: literals for an int128 class Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 16:51 -0400
Re: literals for an int128 class Ian Collins <ian-news@hotmail.com> - 2011-05-04 08:53 +1200
Re: literals for an int128 class Pete Becker <pete@versatilecoding.com> - 2011-05-03 17:17 -0400
Re: literals for an int128 class Michael Doubez <michael.doubez@free.fr> - 2011-05-04 01:38 -0700
Re: literals for an int128 class Ian Collins <ian-news@hotmail.com> - 2011-05-04 21:15 +1200
Re: literals for an int128 class Michael Doubez <michael.doubez@free.fr> - 2011-05-06 01:03 -0700
Re: literals for an int128 class Pete Becker <pete@versatilecoding.com> - 2011-05-06 08:00 -0400
Re: literals for an int128 class Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-06 09:30 -0400
Re: literals for an int128 class Michael Doubez <michael.doubez@free.fr> - 2011-05-06 08:00 -0700
| From | cps <chrissusie8@gmail.com> |
|---|---|
| Date | 2011-05-03 13:39 -0700 |
| Subject | literals for an int128 class |
| Message-ID | <8ec2c079-9c65-462a-a4b2-af8f2f0422ce@p7g2000yqd.googlegroups.com> |
I am considering writing an int128 class as a programming exercise.
Before I start (and I have a fair idea of how to do it) I was
wondering what I can do about literals and the assignment operator. I
would like to be able to use integer literals with the assignment and
other operators with literals that are sized at 128 bits.
E.g. I'd like to be able to do:
uint128 myInt128 = 184467440737095516160;
Note that the foregoing literal would produce an error (correctly
so) if I attempted to assign it to an uint64 because it is (2^64) *
10.
Is there any way I can set it up to deal with large literals?
Or am I going to have to use strings and parse them?
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-05-03 16:51 -0400 |
| Message-ID | <ippps8$cfo$1@dont-email.me> |
| In reply to | #4635 |
On 5/3/2011 4:39 PM, cps wrote:
> I am considering writing an int128 class as a programming exercise.
> Before I start (and I have a fair idea of how to do it) I was
> wondering what I can do about literals and the assignment operator.
Judging from the excerpt below, you're talking about the symbol '=' used
for initialization of objects at the time of their definition, and *NOT*
about the assignment operator.
> I
> would like to be able to use integer literals with the assignment and
> other operators with literals that are sized at 128 bits.
>
> E.g. I'd like to be able to do:
>
> uint128 myInt128 = 184467440737095516160;
That is called initialization.
> Note that the foregoing literal would produce an error (correctly
> so) if I attempted to assign it to an uint64 because it is (2^64) *
> 10.
>
> Is there any way I can set it up to deal with large literals?
Not portably. Literals are defined by the standard/compiler and unless
your compiler already provides a 128 bit signed or unsigned integer
literal, you can't introduce it. If 'uint128' is totally your own
custom class, then your best bet is to introduce a constructor from a
character string (uint128::uint128(const char*)) and surround those
digits with double quotes:
uint128 myInt128("184467440737095516160");
*Some* compilers can offer built-in integral types of that size and with
those they usually offer a way to specify a literal by means of some
suffix. For instance, MS used to have i64 suffix before 64 bit targets
became common:
int64_t ms64bitInteger = 1234567890i64; // if memory serves
> Or am I going to have to use strings and parse them?
Most likely.
T
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-05-04 08:53 +1200 |
| Message-ID | <92b8aeFj03U13@mid.individual.net> |
| In reply to | #4635 |
On 05/ 4/11 08:39 AM, cps wrote: > I am considering writing an int128 class as a programming exercise. > Before I start (and I have a fair idea of how to do it) I was > wondering what I can do about literals and the assignment operator. I > would like to be able to use integer literals with the assignment and > other operators with literals that are sized at 128 bits. > > E.g. I'd like to be able to do: > > uint128 myInt128 = 184467440737095516160; > > > Note that the foregoing literal would produce an error (correctly > so) if I attempted to assign it to an uint64 because it is (2^64) * > 10. > > Is there any way I can set it up to deal with large literals? > > Or am I going to have to use strings and parse them? The only way a system could have 128 bit literals would be if it had a 128 bit type! You'll have to settle for strings. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Pete Becker <pete@versatilecoding.com> |
|---|---|
| Date | 2011-05-03 17:17 -0400 |
| Message-ID | <2011050317171672135-pete@versatilecodingcom> |
| In reply to | #4635 |
On 2011-05-03 16:39:35 -0400, cps said:
> I am considering writing an int128 class as a programming exercise.
> Before I start (and I have a fair idea of how to do it) I was
> wondering what I can do about literals and the assignment operator. I
> would like to be able to use integer literals with the assignment and
> other operators with literals that are sized at 128 bits.
>
> E.g. I'd like to be able to do:
>
> uint128 myInt128 = 184467440737095516160;
>
>
> Note that the foregoing literal would produce an error (correctly
> so) if I attempted to assign it to an uint64 because it is (2^64) *
> 10.
>
> Is there any way I can set it up to deal with large literals?
>
> Or am I going to have to use strings and parse them?
You can't do 128 bit literals if your compiler doesn't support them,
but you can do something that's a little easier than parsing a string.
struct uint128 {
uint128(unsigned long long word1, unsigned long long word0);
};
uint128 i0(0x21, 0x03);
uint128 i1(0x0, 3);
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
[toc] | [prev] | [next] | [standalone]
| From | Michael Doubez <michael.doubez@free.fr> |
|---|---|
| Date | 2011-05-04 01:38 -0700 |
| Message-ID | <ad75ebc6-5f03-4f1b-aa58-2e59d6cfc1ca@r20g2000yqd.googlegroups.com> |
| In reply to | #4635 |
On 3 mai, 22:39, cps <chrissus...@gmail.com> wrote:
> I am considering writing an int128 class as a programming exercise.
> Before I start (and I have a fair idea of how to do it) I was
> wondering what I can do about literals and the assignment operator. I
> would like to be able to use integer literals with the assignment and
> other operators with literals that are sized at 128 bits.
>
> E.g. I'd like to be able to do:
>
> uint128 myInt128 = 184467440737095516160;
>
> Note that the foregoing literal would produce an error (correctly
> so) if I attempted to assign it to an uint64 because it is (2^64) *
> 10.
>
> Is there any way I can set it up to deal with large literals?
>
> Or am I going to have to use strings and parse them?
Parsing it from string is however a good idea.
With C++0x, you will be able to write:
uint128 operator "" ulll(const char * string_values, size_t
num_chars)
{
return uint128::parse(string_values,num_chars);
}
uint128 myInt128 = 184467440737095516160ulll;
--
Michael
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-05-04 21:15 +1200 |
| Message-ID | <92cjpeFj03U17@mid.individual.net> |
| In reply to | #4661 |
On 05/ 4/11 08:38 PM, Michael Doubez wrote:
> On 3 mai, 22:39, cps<chrissus...@gmail.com> wrote:
>> I am considering writing an int128 class as a programming exercise.
>> Before I start (and I have a fair idea of how to do it) I was
>> wondering what I can do about literals and the assignment operator. I
>> would like to be able to use integer literals with the assignment and
>> other operators with literals that are sized at 128 bits.
>>
>> E.g. I'd like to be able to do:
>>
>> uint128 myInt128 = 184467440737095516160;
>>
>> Note that the foregoing literal would produce an error (correctly
>> so) if I attempted to assign it to an uint64 because it is (2^64) *
>> 10.
>>
>> Is there any way I can set it up to deal with large literals?
>>
>> Or am I going to have to use strings and parse them?
>
> Parsing it from string is however a good idea.
>
> With C++0x, you will be able to write:
>
> uint128 operator "" ulll(const char * string_values, size_t
> num_chars)
> {
> return uint128::parse(string_values,num_chars);
> }
>
> uint128 myInt128 = 184467440737095516160ulll;
Neat. In which section of the standard is this described?
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Michael Doubez <michael.doubez@free.fr> |
|---|---|
| Date | 2011-05-06 01:03 -0700 |
| Message-ID | <519895ad-042c-4d66-a756-c95c129677f3@x3g2000yqj.googlegroups.com> |
| In reply to | #4663 |
On 4 mai, 11:15, Ian Collins <ian-n...@hotmail.com> wrote:
> On 05/ 4/11 08:38 PM, Michael Doubez wrote:
>
>
>
>
>
>
>
>
>
> > On 3 mai, 22:39, cps<chrissus...@gmail.com> wrote:
> >> I am considering writing an int128 class as a programming exercise.
> >> Before I start (and I have a fair idea of how to do it) I was
> >> wondering what I can do about literals and the assignment operator. I
> >> would like to be able to use integer literals with the assignment and
> >> other operators with literals that are sized at 128 bits.
>
> >> E.g. I'd like to be able to do:
>
> >> uint128 myInt128 = 184467440737095516160;
>
> >> Note that the foregoing literal would produce an error (correctly
> >> so) if I attempted to assign it to an uint64 because it is (2^64) *
> >> 10.
>
> >> Is there any way I can set it up to deal with large literals?
>
> >> Or am I going to have to use strings and parse them?
>
> > Parsing it from string is however a good idea.
>
> > With C++0x, you will be able to write:
>
> > uint128 operator "" ulll(const char * string_values, size_t
> > num_chars)
> > {
> > return uint128::parse(string_values,num_chars);
> > }
>
> > uint128 myInt128 = 184467440737095516160ulll;
>
> Neat. In which section of the standard is this described?
In the current draft (n3242)
2.14.8 User-defined literals [lex.ext]
--
Michael
[toc] | [prev] | [next] | [standalone]
| From | Pete Becker <pete@versatilecoding.com> |
|---|---|
| Date | 2011-05-06 08:00 -0400 |
| Message-ID | <2011050608001631718-pete@versatilecodingcom> |
| In reply to | #4764 |
On 2011-05-06 04:03:13 -0400, Michael Doubez said: > > In the current draft (n3242) > The current draft is N3291. -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-05-06 09:30 -0400 |
| Message-ID | <iq0t5n$jl2$1@dont-email.me> |
| In reply to | #4771 |
On 5/6/2011 8:00 AM, Pete Becker wrote:
> On 2011-05-06 04:03:13 -0400, Michael Doubez said:
>
>>
>> In the current draft (n3242)
>>
>
> The current draft is N3291.
>
Huh...
One would expect it be linked to on the Committee's page
http://www.open-std.org/jtc1/sc22/wg21/
, yet the link still points to n3242... Just to let you know... In
case you somehow can influence what's put on that web page...
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Michael Doubez <michael.doubez@free.fr> |
|---|---|
| Date | 2011-05-06 08:00 -0700 |
| Message-ID | <1114434f-f66d-4106-83df-9583b124a038@f9g2000vbz.googlegroups.com> |
| In reply to | #4771 |
On 6 mai, 14:00, Pete Becker <p...@versatilecoding.com> wrote: > On 2011-05-06 04:03:13 -0400, Michael Doubez said: > > > In the current draft (n3242) > > The current draft is N3291. Thanks. I just grabbed it from WG21 page. Is there any hope that c++1x or C++2x will make it to N4242 ? -- Michael
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web