public override int GetHashCode() { unchecked { return((RealPart.GetHashCode() * 397) ^ ImaginaryPart.GetHashCode()); } }
public void ShouldSucceed() { var rb = new RegistrationBuilder(); rb.ForType<RealPart>().Export(); var cat = new AssemblyCatalog(typeof(RegistrationBuilderTests).Assembly, rb); var container = new CompositionContainer(cat); // Throws: // Can not determine which constructor to use for the type 'System.ComponentModel.Composition.Hosting.AssemblyCatalog, System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. RealPart rp = container.GetExport<RealPart>().Value; }
public bool Equals(Constant other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(RealPart.Equals(other.RealPart) && ImaginaryPart.Equals(other.ImaginaryPart)); }
public string ToInline() { var real = RealPart.ToInline(); var imaginary = ImaginaryPart.IsInteger && (long)ImaginaryPart.AbsoluteValue == 1 ? "i" : $"{Absolute(ImaginaryPart).ToInline()}i"; return(IsReal ? RealPart.ToString() : ImaginaryPart.Value > 0 ? $"({real} + {imaginary})" : $"({real} - {imaginary})"); }
/// <summary> /// accepted format is "R_{whatever format for the double real value}_{whatever format for the double imaginary value}" or /// "P_{whatever format for the double radius}_({whatever format for the angle}) /// the last argument can be discarded to be replaced by the second /// </summary> /// <param name="format"></param> /// <param name="provider"></param> /// <returns></returns> public string ToString(string format, IFormatProvider provider) { if (format == "") { format = "R_G_G"; } string[] split = format.SmartSplit("_", "(", ")"); if (split.Length == 1) { split = new[] { split[0], "G", "G" } } ; if (split.Length == 2) { split = new[] { split[0], split[1], split[1] } } ; if (split.Length != 3) { throw new FormatException("Format must either be empty or include 1 or 2 dividers (_)"); } if (split[0] == "R") { string realformat = split[1]; string imagformat = split[2]; if (Isreal()) { return(RealPart.ToString(realformat, provider)); } if (Isimaginary()) { return(ImaginaryPart.ToString(imagformat, provider) + "i"); } return(RealPart.ToString(realformat, provider) + (ImaginaryPart < 0 ? "" : "+") + ImaginaryPart.ToString(imagformat, provider) + "i"); } if (split[1] == "P") { string radiusformat = split[1]; string angleformat = split[2]; if (Radius == 1) { return("CiS(" + Angle.ToString(angleformat) + ")"); } if (Radius == 0) { return("0"); } return(Radius.ToString(radiusformat, provider) + "CiS(" + Angle.ToString(angleformat) + ")"); } throw new FormatException("Format must either be empty or start with a R or a P"); }
public int CompareTo(ComplexNumber other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } var realRartComparison = RealPart.CompareTo(other.RealPart); return(realRartComparison != 0 ? realRartComparison : ImagPart.CompareTo(other.ImagPart)); }
public string ToJson(bool pretty = false) { return(JsonSerializer .Serialize(new { Magnitude = Magnitude.ToInline(), Argument = Argument.ToString(), RealPart = RealPart.ToInline(), ImaginaryPart = RealPart.ToInline() }, new JsonSerializerOptions { WriteIndented = pretty, Encoder = pretty ? JavaScriptEncoder.UnsafeRelaxedJsonEscaping : JavaScriptEncoder.Default })); }
public bool isGaussianPrime() { if (Iszero() || !IsGaussian()) { return(false); } if (Iscomplex()) { return(((int)(RealPart * RealPart + ImaginaryPart * ImaginaryPart)).IsPrime()); } if (ImaginaryPart == 0) { return(((int)RealPart.abs()).TrueMod(4) == 3 && ((int)RealPart.abs()).IsPrime()); } return(((int)ImaginaryPart.abs()).TrueMod(4) == 3 && ((int)ImaginaryPart.abs()).IsPrime()); }
/*_________________________________________________________Обработка_событий_______________________________________________________*/ #region Event handles private void JuliaEditor_Load(object sender, EventArgs e) { LeftEdgeEdit.Text = LeftEdge.ToString(); RightEdgeEdit.Text = RightEdge.ToString(); TopEdgeEdit.Text = TopEdge.ToString(); BottomEdgeEdit.Text = BottomEdge.ToString(); RealPartEdit.Text = RealPart.ToString(); ImaginePartEdit.Text = ImaginePart.ToString(); LeftEdgeEdit.KeyPress += FormEventHandlers.OnlyNumeric; RightEdgeEdit.KeyPress += FormEventHandlers.OnlyNumeric; TopEdgeEdit.KeyPress += FormEventHandlers.OnlyNumeric; BottomEdgeEdit.KeyPress += FormEventHandlers.OnlyNumeric; RealPartEdit.KeyPress += FormEventHandlers.OnlyNumeric; ImaginePartEdit.KeyPress += FormEventHandlers.OnlyNumeric; EditDescriptor.SetToolTip(LeftEdgeLabel, FractalGlobalDescriptions.LeftEdgeOf2DFractal); EditDescriptor.SetToolTip(LeftEdgeEdit, "Здесь необходимо вводить левую границу двухмерного фрактала джулии (десятиричное представления числа).\n" + FractalGlobalDescriptions.LeftEdgeOf2DFractal); EditDescriptor.SetToolTip(RightEdgeLabel, FractalGlobalDescriptions.RightEdgeOf2DFractal); EditDescriptor.SetToolTip(RightEdgeEdit, "Здесь необходимо вводить правую границу двухмерного фрактала джулии (десятиричной представления числа, в качестве разделителей на дроную часть используйте \",\" или \".\").\n" + FractalGlobalDescriptions.RightEdgeOf2DFractal); GlobalTemplates.SetTemplate(MainPanelOfJuliaEditor, "Шрифт окна для ввода фрактала джулии"); }
public int CompareTo(Complex other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } var realPartComparison = RealPart.CompareTo(other.RealPart); if (realPartComparison != 0) { return(realPartComparison); } return(VirtualPart.CompareTo(other.VirtualPart)); }
public override bool Equals(object obj) { var complexnum = obj as ComplexNumber; if (complexnum != null) { return(complexnum.RealPart == RealPart && complexnum.ImaginaryPart == ImaginaryPart); } if (!Isreal()) { return(false); } try { return(RealPart.Equals(Convert.ToDouble(obj))); } catch (Exception) { return(false); } }
public override int GetHashCode() { return(RealPart.GetHashCode() ^ ImaginaryPart.GetHashCode() ^ Angle.GetHashCode()); }
private bool Equals(ComplexNumber other) { return(RealPart.Equals(other.RealPart) && ImagPart.Equals(other.ImagPart)); }