posts - 19 , comments - 8 , trackbacks - 0

November 2014 Entries

A Rational Number Class in C#
Overview The following code implements a rational number. The code I have split the code into partial classes to keep the functionality distinct.For the underlying types I have decided to use longs throughout as the main problem with rational numbers is overflow. Furthermore I have chosen to always reduce the fraction. This adds an overhead on each computation, but contains overflow problems. AlgorithmsThe first task is to write the greatest common divisor function. From my previous post I have established ......

Posted On Friday, November 14, 2014 11:02 AM | Comments (2) | Filed Under [ C# rational fraction ]

Evaluating the Greatest Common Divisor function in C#
Available Routines There are a number of basic routines. Two that are attributable to Euclid are the subtraction and modulus method. There is another routine be Stein which uses binary arithmatic. Lastly there is the "trial and error" version which is useful as a check on validity. The algorithms The algorithms are provided in the code below. using System; namespace JetBlack.Common { public static class GreatestCommonDivisor { public enum Algorithm { TrialAndError, EuclidModulus, EuclidModulusShort, ......

Posted On Friday, November 14, 2014 10:56 AM | Comments (0) | Filed Under [ C# GCD greatest common divisor ]

Powered by: