------------------------------------------------------------------------- Subject: Readme file for big number arithmetic in a spreadsheet. Date : 06-06-2009 Code : VBA adaptation for Excel 8.0 ------------------------------------------------------------------------- File "bignumXL.cls" consists of "bignumVB.bi" with Private Declare's, and a few self-initializing functions to operate on rational and real big numbers in a spreadsheet. First copy file ".\common\bignumVB.dll" to the Excel startup directory, and import the bignum class to your project via visual basic editor. Make sure to set the cell format to General, double-click to compute. Results adhere to the operand types, but mixing reals with rationals always returns a real, as well as functions L_Sqrt and L_CDec. As Excel cuts off strings longer than 1024 characters, any rational exceeding this size is converted to a decimal fraction with exponent. ------------------------------------------------------------------------- Contents: Macro SetPrec() Set the decimal precision, default = 60. L_Sum(x()) Return the sum of the cellranges. L_Sub(x, y) Return x - y. L_Mul(x()) Return product of the cellranges. L_Div(x, y) Return x / y. L_Squ(x) Return x * x. L_Pow(x, k) Return x ^ k, with integral exponent. L_Inv(x) Return 1 / x. L_Sqrt(x) Return real square root(x). L_Mod(a, n) Return a modulo n, with integral modulus. L_Modpwr(a, k, n) Return a ^ k modulo n, with integral exponent and modulus. L_NxtPrm(n) Return the next prime greater than or equal to n. L_TinyFact(n) Return small primefactors of n using trial division. L_Fctl(k) Return factorial(k). L_Bino(n, k) Return (n choose k). L_CDec(a) Convert rational argument to decimal fraction. L_CRat(x, d) Approximate real by rational with denominator less than or equal to d. ------------------------------------------------------------------------- Examples: three famous recurrences 1) Fibonacci numbers Set up | A | ------- 1 | 0 | -------- 2 | 1 | --------- 3 |=L_Sum(A1,A2) ---------- then select (n-1) cells in column A, with A3 on top. Choose Edit > Fill > Down (or Ctrl + D), press F9 to compute. 2) Binomial coefficients Set up | A | B | ----------- 1 | 0 | 1 | ------------ 2 | 0 |=L_Sum(A1,B1) ------------- select n × (1 + n\2) range, with B2 in the upper left corner. Press Ctrl + R, Ctrl + D (fill right and down), F9 to compute. (Or erase cells with column > row + 1 to make a triangle) 3) Bernoulli numbers Set up | A | ------- 1 |=L_Inv(Column()) -------- then select n cells in row 1, including A1. Press Ctrl + R to fill right and F9 to compute. | A | B | --------------- 1 | 1 | 1/2 | ... -------------------- 2 |=L_Mul(Column(),L_Sub(A1,B1)) --------------------- select (n-1) × (n-1) range, with A2 in upper left corner. Press Ctrl + R, Ctrl + D (fill right and down), F9 to compute. (Or erase cells with column > n - row + 1 to make a triangle)