public bool IsZero() { if (NumMonof.Count() == 0 || DenMonof.Count() == 0) { return(true); } return(NumMonof.All(x => x.IsZero()) && DenMonof.All(x => x.IsZero())); }
public override int GetHashCode() { var hash = 1; if (NumMonof.Count() != 0) { hash ^= NumMonof.Select(x => x.GetHashCode()).Aggregate((now, next) => now ^ next); } if (DenMonof.Count() != 0) { hash ^= DenMonof.Select(x => - x.GetHashCode()).Aggregate((now, next) => now ^ next); } return(hash); }
public bool IsOne() { return(NumMonof.Count() == 1 && NumMonof[0].IsOne() && DenMonof.Count() == 1 && DenMonof[0].IsOne()); }
public async Task <string> GetString(bool ReturnFraction = false, bool ForDisplay = false) { string NumStr = ""; if (NumMonof.Count() == 0) { return("0"); } else { NumStr = (await NumMonof.Select(async x => { var str = await x.GetString(ReturnFraction, ForDisplay); if (str == "") { return(""); } else if (str.First() == '-') { return(str); } else { return("+" + str); } }).WhenAll()).Aggregate((now, next) => now + next); if (NumStr != "" && NumStr.First() == '+') { NumStr = NumStr.Substring(1); } } if (DenMonof.Count() == 1 && DenMonof[0].IsOne()) { return(NumStr); } else { var DenStr = (await DenMonof.Select(async x => { var str = await x.GetString(ReturnFraction, ForDisplay); if (str == "") { return(""); } else if (str.First() == '-') { return(str); } else { return("+" + str); } }).WhenAll()).Aggregate((now, next) => now + next); if (DenStr != "" && DenStr.First() == '+') { DenStr = DenStr.Substring(1); } if (DenStr == "1" || DenStr == "") { return(NumStr); } if (NumStr.Contains("+") || NumStr.Substring(1).Contains("-")) { NumStr = "(" + NumStr + ")"; } if (DenStr.Contains("+") || DenStr.Substring(1).Contains("-")) { DenStr = "(" + DenStr + ")"; } return(NumStr + "/" + DenStr); } }