예제 #1
0
            private void CalculateFractionRepresentations(JereNumber number)
            {
                IsNegative = number._denominator == 0 || number._numerator == 0 ? false : number._numerator * number._denominator < 0;
                IsZero     = number._numerator == 0 && number._denominator != 0;

                OriginalNumerator   = number.OriginalNumerator;
                OriginalDenominator = number.OriginalDenominator;
                AsOriginalFraction  = $"{OriginalNumerator}/{OriginalDenominator}";

                SimplifiedNumerator   = number._numerator;
                SimplifiedDenominator = number._denominator;

                //undefined already taken care of
                if (IsZero)
                {
                    AsFraction         = $"{SimplifiedNumerator}/{SimplifiedDenominator}";
                    AsFractionIsNoLoss = true;
                    AsFractionNoLoss   = $"{SimplifiedNumerator}/{SimplifiedDenominator}";
                }
                else
                {
                    AsFraction = $"{SimplifiedNumerator}/{SimplifiedDenominator}";
                    if (SimplifiedNumerator.SignificantDigits() < 28 &&
                        SimplifiedDenominator.SignificantDigits() < 28)
                    {
                        AsFractionIsNoLoss = true;
                        AsFractionNoLoss   = $"{SimplifiedNumerator}/{SimplifiedDenominator}";
                    }
                }
            }
예제 #2
0
        }                                     //todo as more complicated algebraic forms

        public Expression(string originalForm)
        {
            OriginalForm = originalForm;

            if (RegexPatterns.MixedNumberOrFractionOrNumber.IsMatch(originalForm))
            {
                AsNumber       = new JereNumber(originalForm);
                IsNumber       = true;
                Representation = AsNumber.Representation;
            }
            else if (RegexPatterns.Point2DList.IsMatch(originalForm))
            {
                AsCartesian2dPoints = new Cartesian2DPoints(originalForm);
                IsCartesian2dPoints = true;
                Representation      = AsCartesian2dPoints.ToString();
            }
            else if (RegexPatterns.DisplacementVector.IsMatch(originalForm))
            {
                AsDisplacementVector = new DisplacementVector(originalForm);
                IsDisplacementVector = true;
            }
            else
            {
                throw new NotImplementedException("wurkin on it");
            }
        }
예제 #3
0
 private void ProcessDecimal(JereNumber number)
 {
     AsDecimal = (decimal)number._numerator / (decimal)number._denominator;
     //if longer than 28 decimal places = approximate, not rational
     //if has repeating decimal pattern, and longer than 28 decimal places = approximate, rational
     //https://stackoverflow.com/questions/1315595/algorithm-for-detecting-repeating-decimals
     //http://mathworld.wolfram.com/DecimalExpansion.html
     //https://softwareengineering.stackexchange.com/questions/192070/what-is-a-efficient-way-to-find-repeating-decimal
     //https://www.exceptionnotfound.net/decimal-vs-double-and-other-tips-about-number-types-in-net/
     //https://fiziko.bureau42.com/teaching_tidbits/turning_repeating_decimals_into_fractions.pdf
     //https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types
     //https://docs.microsoft.com/en-us/dotnet/api/system.decimal.compareto?view=netframework-4.8#System_Decimal_CompareTo_System_Decimal_
     //.compareTo() and equals()
     //a decimal may have precision of 28-29, does that include left and right? yes
     //Precision is 28-29, scale is # of digits after decimal point
     //Use brute force method for now
     if (AsDecimal.SignificantDigits() < 28) //No loss
     {
         AsDecimalIsNoLoss = true;
         AsDecimalNoLoss   = AsDecimal;
         ProcessDecimalNoLoss((decimal)AsDecimalNoLoss);
     }
     else //All lesser types will be approximate too.
     {
         AsInt    = (int)(number._numerator / number._denominator);
         AsLong   = (long)(number._numerator / number._denominator);
         AsDouble = (double)(number._numerator / number._denominator);
     }
 }
예제 #4
0
            private bool ProcessFraction(JereNumber number)
            {
                //IsNegative = number._denominator == 0 || _numerator == 0 ? false : _numerator * number._denominator < 0;
                //IsZero = number._numerator == 0 && number._denominator != 0;

                //OriginalNumerator = number.OriginalNumerator;
                //OriginalDenominator = number.OriginalDenominator;
                //AsOriginalFraction = $"{OriginalNumerator}/{OriginalDenominator}";

                //SimplifiedNumerator = number._numerator;
                //SimplifiedDenominator = number._denominator;
                //SimplifiedAsFraction = $"{SimplifiedNumerator}/{SimplifiedDenominator}";

                return(true);
            }
예제 #5
0
            private void PopulateRepresentations(JereNumber number)
            {
                SimplifiedAsFraction = $"{SimplifiedNumerator}/{SimplifiedDenominator}";
                OriginalAsFraction   = $"{OriginalNumerator}/{OriginalDenominator}";
                CalculateFractionRepresentations(number);
                CalculateMixedNumberRepresentations();

                if (IsZero)
                {
                    DefaultRepresentation = "0";
                }
                else if (AsIntNoLoss.HasValue)
                {
                    DefaultRepresentation = AsIntNoLoss.ToString();
                }
                else if (AsLongNoLoss.HasValue)
                {
                    DefaultRepresentation = AsLongNoLoss.ToString();
                }
                else if (AsDoubleNoLoss.HasValue)
                {
                    DefaultRepresentation = AsDoubleNoLoss.ToString();
                }
                else if (AsDecimalNoLoss.HasValue)
                {
                    DefaultRepresentation = AsDecimalNoLoss.ToString();
                }
                else if (AsMixedNumberNoLoss != null)
                {
                    DefaultRepresentation = AsMixedNumberNoLoss;
                }
                else if (AsFractionNoLoss != null)
                {
                    DefaultRepresentation = AsFractionNoLoss;                                //would this ever hit?
                }
                else
                {
                    DefaultRepresentation = SimplifiedAsFraction;  //last one could be approximation if num or denom over 28 Significants long.
                }
            }
예제 #6
0
 public Point(Expression x, JereNumber y)
 {
     _x = x;
     _y = y;
 }
예제 #7
0
 public Metadata(JereNumber number)
 {
     ProcessDecimal(number);
     PopulateRepresentations(number);
 }
예제 #8
0
 public Variable(Expression numerator, JereNumber denominator, string representation)
 {
     Expression     = new Expression(new JereNumber(numerator, denominator));
     Representation = representation;
     IsKnown        = true;
 }
예제 #9
0
 public Variable(JereNumber numerator, string representation)
 {
     Expression     = numerator;
     Representation = representation;
     IsKnown        = true;
 }
예제 #10
0
 public Point(long x, JereNumber y)
 {
     _x = x;
     _y = y;
 }
예제 #11
0
 public Point(int x, JereNumber y)
 {
     _x = x;
     _y = y;
 }
예제 #12
0
 public Point(JereNumber x, decimal y)
 {
     _x = x;
     _y = y;
 }
예제 #13
0
 public Point(JereNumber x, Expression y)
 {
     _x = x;
     _y = y;
 }
예제 #14
0
 public Point(JereNumber x, double y)
 {
     _x = x;
     _y = (decimal)y;
 }
예제 #15
0
 public Point(JereNumber x, long y)
 {
     _x = x;
     _y = y;
 }
예제 #16
0
 public Point(JereNumber x, int y)
 {
     _x = x;
     _y = y;
 }
예제 #17
0
 public Point(decimal x, JereNumber y)
 {
     _x = x;
     _y = y;
 }
예제 #18
0
 public Point(double x, JereNumber y)
 {
     _x = (decimal)x;
     _y = y;
 }