Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 03 May 2011 16:17:16 -0500 From: Pete Becker Organization: Roundhouse Consulting, Ltd. Newsgroups: comp.lang.c++ Date: Tue, 3 May 2011 17:17:16 -0400 Message-ID: <2011050317171672135-pete@versatilecodingcom> References: <8ec2c079-9c65-462a-a4b2-af8f2f0422ce@p7g2000yqd.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: literals for an int128 class User-Agent: Unison/2.1.4 Lines: 39 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-NyTgTy+XPUmKBirr+8UxNeMnWfQbcm2aor2k0PB3nMvHFQuIqPA15c0uW0G8IzjnVu8bWtNDfELlMuv!DBjZHiDwlGxb0oXFYv75Zjt3OIYm4NyMtZgbJ3B4j3XGubFhXvyla7ixyGvjr08jY5jbVzL1 X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2343 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:4639 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)