Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 23 Oct 2012 07:45:40 -0500 From: Steve Thompson Newsgroups: comp.lang.c Subject: Re: Large number libraries/algorithms Date: Tue, 23 Oct 2012 12:40:48 +0000 Organization: Friends of the Galactic Collective Message-ID: References: <4q6dnXHstpLfshjNnZ2dnUVZ8o-dnZ2d@lyse.net> <0.4b9d32dea7f57a2ad3b4.20121023000110BST.87ipa29knd.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: NN 6.4.3 Lines: 65 X-Trace: sv3-zgZWZ8+EvKeWi/h0xoArvYcHyOZ5Wcj9c90UnElQs8QlUFFT73VkCnpjE0tn3akKGcn4m4dnIftE6kZ!VJzn/yhwTefTiyh4lT9lGq7qTxdldjvAkG9QbQMPxzUMy1qj2MjonRBMcVnZmQ== X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/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: 4022 Xref: csiph.com comp.lang.c:27571 On Tue, Oct 23, 2012 at 09:38:00AM +0200, David Brown wrote: > On 23/10/2012 01:01, Ben Bacarisse wrote: > >Robert Wessel writes: > > > >>On Mon, 22 Oct 2012 10:31:54 -0700, Keith Thompson > >>wrote: > >> > >>>David Brown writes: > >>>>On 22/10/2012 11:11, boltar2003@boltar.world wrote: > >>>>>Does anyone know of an API that will do standard math ops (*,+,-,/,% > >>>>>etc) on > >>>>>very large numbers (stored in char arrays presumably)? ie The sort of > >>>>>numbers > >>>>>that have no chance of fitting in even a 64 bit int or double. Or > >>>>>failing > >>>> > >>>>If your numbers will fit into 128-bit ints, then I think it is quite > >>>>common to support 128-bit types in 64-bit compilers, and they will be > >>>>much more efficient than arbitrarily long number libraries. But that > >>>>only helps if 128 bits is big enough. > >>> > >>>I don't think I've ever seen a C compiler that supports 128-bit > >>>integers. Can you provide an example? > >> > >> > >>Doesn't Jacob Navia's? And GCC on 64 bit targets usually has at least > >>partial support. > > > >It supports a type called int128, but it's not an integer type. For > >example, you can't cast it to another integer type. It's implemented as > >a struct using lcc-win32's operator overloading so it's a matter of > >debate if a program using it is using a "C compiler". Jacob's operator > >overloading is deliberately unobtrusive but I have not studied the > >consequences of not using the compiler in a conforming mode. > > > >gcc provides __int128 "for targets having an integer mode wide enough to > >hold 128-bit". I'm not sure exactly what's included in that. > > > > gcc certainly provides it for 64-bit amd64 targets - and I'm guessing > also for other 64-bit targets (such as PPC, MIPS, IA-64). It is treated > much like any other integer type as far as gcc is concerned. Generated > code will use two registers and twice as many operations compared to > 64-bit integers, but that's standard for C compilers working with > integers wider than the registers. > > It would not surprise me unduly if gcc supported 128-bit integers on > 32-bit targets as well (after all, it happily supports 64-bit integers > on 8-bit targets), but I haven't checked. I was briefly looking at the compiler info pages but I could not easily determine whether support included all the trig/exponential/etc math functions or whether it only supports basic arithmetic operations. In the latter case, it doesn't seem like it would be all that useful. Regards, Steve Thompson -- GOTO's are like guns. Safety is entirely contingent on the user.