Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Large number libraries/algorithms

Reply
Thread Tools

Large number libraries/algorithms

 
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      10-22-2012
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
that is there a good site explaining how to implement them yourself?

Thanks for any info

B2003

 
Reply With Quote
 
 
 
 
Mark Bluemel
Guest
Posts: n/a
 
      10-22-2012
On 22/10/2012 10:11, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
> that is there a good site explaining how to implement them yourself?



A web search for "C bignum" is probably a good start.

 
Reply With Quote
 
 
 
 
Heikki Kallasjoki
Guest
Posts: n/a
 
      10-22-2012
On 2012-10-22, (E-Mail Removed) <(E-Mail Removed)> 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
> that is there a good site explaining how to implement them yourself?


The GNU Multiple Precision Arithmetic Library (GMP) is relatively
popular:

http://gmplib.org/
http://gmplib.org/manual/Integer-Functions.html


--
Heikki Kallasjoki
 
Reply With Quote
 
Noob
Guest
Posts: n/a
 
      10-22-2012
boltar2003 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
> that is there a good site explaining how to implement them yourself?


https://en.wikipedia.org/wiki/Arbitr...ion_arithmetic

fefe's comparison:
http://dl.fefe.de/bignum.pdf

TomsFastMath:
http://libtom.org/?page=features&whatfile=tfm
https://github.com/libtom/tomsfastma...er/doc/tfm.pdf

Regards.

 
Reply With Quote
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      10-22-2012
On Mon, 22 Oct 2012 09:19:52 GMT
Heikki Kallasjoki <(E-Mail Removed)> wrote:
>On 2012-10-22, (E-Mail Removed) <(E-Mail Removed)> 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
>> that is there a good site explaining how to implement them yourself?

>
>The GNU Multiple Precision Arithmetic Library (GMP) is relatively
>popular:
>
> http://gmplib.org/
> http://gmplib.org/manual/Integer-Functions.html


Thanks, thats just what I need.

B2003

 
Reply With Quote
 
boltar2003@boltar.world
Guest
Posts: n/a
 
      10-22-2012
On Mon, 22 Oct 2012 13:29:51 +0200
David Brown <(E-Mail Removed)> wrote:
>On 22/10/2012 11:11, (E-Mail Removed) 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
>> that is there a good site explaining how to implement them yourself?
>>
>> Thanks for any info
>>
>> B2003
>>

>
>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


I didn't know that. Whats the C type definition for 128 bit ints?

B2003


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-22-2012
On 10/22/2012 07:53 AM, (E-Mail Removed) wrote:
> On Mon, 22 Oct 2012 13:29:51 +0200
> David Brown <(E-Mail Removed)> wrote:

....
>> 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

>
> I didn't know that. Whats the C type definition for 128 bit ints?


[u]in128_t, [u]int_least128_t, [u]int_fast128_t. They're not guaranteed
to be supported, but those names are reserved for that use, and you can
check whether or not the corresponding macros in <stdint.h> are
#defined; they are not allowed to be #defined unless the corresponding
types are supported.
--
James Kuyper
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      10-22-2012
On 10/22/2012 5:11 AM, (E-Mail Removed) 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
> that is there a good site explaining how to implement them yourself?


This is Question 18.15d on the comp.lang.c Frequently Asked
Questions (FAQ) page at <http://www.c-faq.com/>.

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      10-22-2012
On 10/22/2012 08:41 AM, David Brown wrote:
> On 22/10/2012 14:01, James Kuyper wrote:

....
>> [u]in128_t, [u]int_least128_t, [u]int_fast128_t. They're not guaranteed
>> to be supported, but those names are reserved for that use, and you can
>> check whether or not the corresponding macros in <stdint.h> are
>> #defined; they are not allowed to be #defined unless the corresponding
>> types are supported.
>>

>
> I don't know whether these are necessarily supported by compilers


I do. They aren't. I already said so above.

> ... (but
> if your compiler has them, then use them). Other possibilities are
> __int128 (and unsigned __int12, or "long long int".


A conforming implementation of C90 can support long long only as an
extension. An implementation that conforms to either C99 or C2011, and
supports any 128-bit type (with no padding bits, and if signed, 2's
complement representation), has no excuse for not supporting the
corresponding <stdint.h> types. Therefore, looking for other names is
mainly needed only if you're using a C90 implementation that supports
128-bit types. I'm not sure how common those are - but I'd expect them
to be rare.
--
James Kuyper
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      10-22-2012
James Kuyper <(E-Mail Removed)> writes:

> On 10/22/2012 08:41 AM, David Brown wrote:
>> On 22/10/2012 14:01, James Kuyper wrote:

> ...
>>> [u]in128_t, [u]int_least128_t, [u]int_fast128_t. They're not guaranteed
>>> to be supported, but those names are reserved for that use, and you can
>>> check whether or not the corresponding macros in <stdint.h> are
>>> #defined; they are not allowed to be #defined unless the corresponding
>>> types are supported.
>>>

>>
>> I don't know whether these are necessarily supported by compilers

>
> I do. They aren't. I already said so above.
>
>> ... (but
>> if your compiler has them, then use them). Other possibilities are
>> __int128 (and unsigned __int12, or "long long int".

>
> A conforming implementation of C90 can support long long only as an
> extension. An implementation that conforms to either C99 or C2011, and
> supports any 128-bit type (with no padding bits, and if signed, 2's
> complement representation), has no excuse for not supporting the
> corresponding <stdint.h> types. Therefore, looking for other names is
> mainly needed only if you're using a C90 implementation that supports
> 128-bit types.


You also need to look for them for purely practical reasons. For
example, with my gcc version, there is a 128-bit integer type meeting
all the right conditions but int128_t does not exist in c99 mode. The
reason, I imagine, is that compiler and library development are somewhat
separate in gcc, so it's easier to keep stdint.h (and glibc's printf
family) at some sort of "lowest common denominator" level.

> I'm not sure how common those are - but I'd expect them
> to be rare.


--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
median of large data set (from large file) friend.05@gmail.com Perl Misc 5 04-02-2009 04:06 AM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
how to in INSTANTIATING large number of components? nospam VHDL 4 06-06-2005 06:47 AM
[Urgent] Is there a size limit on returning a large dataset or a large typed array from web service? Ketchup ASP .Net Web Services 1 05-25-2004 10:11 AM
Backing Up Large Files..Or A Large Amount Of Files Scott D. Weber For Unuathorized Thoughts Inc. Computer Support 1 09-19-2003 07:28 PM



Advertisments