Pascal’s Triangle in C

Factorials get really big really fast (scroll down a little to see the list). Even a 64-bit number is only good up to 20!. So you have to do a little preprocessing before you start multiplying. The general idea is to factor the numerator and the denominator, and remove all of the common factors. Since … Read more

How to work with large numbers in R?

As Livius points out in his comment, this is an issue with R (and in fact, most programming language), with how numbers are represented in binary. To work with extremely large/small floating point numbers, you can use the Rmpfr library: install.packages(“Rmpfr”) library(“Rmpfr”) x <- c(-2.5e+59, -5.6e+60) y <- mpfr(x, 6) # the second number is … Read more

Big integers in C#

As of .NET 4.0 you can use the System.Numerics.BigInteger class. See documentation here: http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(v=vs.110).aspx Another alternative is the IntX class. IntX is an arbitrary precision integers library written in pure C# 2.0 with fast – O(N * log N) – multiplication/division algorithms implementation. It provides all the basic operations on integers like addition, multiplication, comparing, … Read more