Ejemplo n.º 1
0
 /// <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");
 }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
0
 public override int GetHashCode()
 {
     return(RealPart.GetHashCode() ^ ImaginaryPart.GetHashCode() ^ Angle.GetHashCode());
 }