// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; using Microsoft.FSharp.Math; namespace E { public static class MyBigNumExts { public static BigInt Factorial(int n) { if(n > 1) { return BigInt.FromInt32(n) * Factorial(n - 1); } else { return BigInt.One; } } public static string MyToString(this BigNum x, int nodec) { StringBuilder sb = new StringBuilder(); BigInt n = x.Numerator; BigInt d = x.Denominator; BigInt intpart = n / d; sb.Append(intpart.ToString()); n = n - intpart * d; sb.Append("."); for (int i = 0; i < nodec; i++) { n = n * BigInt.FromInt32(10); intpart = n / d; sb.Append(intpart.ToString()); n = n - intpart * d; } return sb.ToString(); } } public class Program { public static void Main(string[] args) { for (int i = 0; i < 50; i++) { Console.WriteLine(MyBigNumExts.Factorial(i)); Console.WriteLine(BigInt.Factorial(BigInt.FromInt32(i))); } for (int i = 0; i < 50; i++) { Console.WriteLine(BigNum.PowN(BigNum.FromInt(10), i)); } for (int i = 0; i < 50; i++) { Console.WriteLine(BigNum.PowN(BigNum.FromInt(10), i)); } for (int i = 0; i < 50; i++) { Console.WriteLine(BigNum.PowN(BigNum.FromInt(10), i)); } BigNum onethird = BigNum.One / BigNum.FromInt(3); Console.WriteLine(onethird.ToString()); Console.WriteLine(onethird.MyToString(30)); } } }