Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Large number libraries/algorithms (http://www.velocityreviews.com/forums/t953721-large-number-libraries-algorithms.html)

boltar2003@boltar.world 10-22-2012 09:11 AM

Large number libraries/algorithms
 
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


Mark Bluemel 10-22-2012 09:15 AM

Re: Large number libraries/algorithms
 
On 22/10/2012 10: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
> that is there a good site explaining how to implement them yourself?



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


Heikki Kallasjoki 10-22-2012 09:19 AM

Re: Large number libraries/algorithms
 
On 2012-10-22, boltar2003@boltar.world <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
> 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

Noob 10-22-2012 09:24 AM

Re: Large number libraries/algorithms
 
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.


boltar2003@boltar.world 10-22-2012 09:40 AM

Re: Large number libraries/algorithms
 
On Mon, 22 Oct 2012 09:19:52 GMT
Heikki Kallasjoki <fis+usenet@zem.fi> wrote:
>On 2012-10-22, boltar2003@boltar.world <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
>> 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


boltar2003@boltar.world 10-22-2012 11:53 AM

Re: Large number libraries/algorithms
 
On Mon, 22 Oct 2012 13:29:51 +0200
David Brown <david@westcontrol.removethisbit.com> wrote:
>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
>> 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



James Kuyper 10-22-2012 12:01 PM

Re: Large number libraries/algorithms
 
On 10/22/2012 07:53 AM, boltar2003@boltar.world wrote:
> On Mon, 22 Oct 2012 13:29:51 +0200
> David Brown <david@westcontrol.removethisbit.com> 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

Eric Sosman 10-22-2012 12:23 PM

Re: Large number libraries/algorithms
 
On 10/22/2012 5:11 AM, 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
> 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
esosman@comcast-dot-net.invalid

James Kuyper 10-22-2012 01:36 PM

Re: Large number libraries/algorithms
 
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 __int128), 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

Ben Bacarisse 10-22-2012 02:12 PM

Re: Large number libraries/algorithms
 
James Kuyper <jameskuyper@verizon.net> 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 __int128), 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.


All times are GMT. The time now is 06:44 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.