Esempio n. 1
0
        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})");
        }
Esempio n. 2
0
 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
     }));
 }