I find that the string representation of the complex numbers defined on the 
complex module could be improved. Currently they are just represented as 
tuples. Instead I think it would be much nicer if nim did an arithmetic 
representation (e.g. 1.5-2.2j). Do you think that would be a good idea?

That is, rather than:
    
    
    proc `$`*(z: Complex): string =
      ## Returns `z`'s string representation as ``"(re, im)"``.
      result = "(" & $z.re & ", " & $z.im & ")"
    

I'd prefer if nim did something like:
    
    
    proc `$`*(z: Complex): string =
      ## Returns `z`'s string representation (e.g. 2.1-1.3j).
      result =
        if z.im == 0.0:
          $z.re
        elif z.re == 0.0:
          $z.im & "j"
        elif z.im < 0.0:
          $z.re & "-" & $(-z.im) & "j"
        else:
          $z.re & "+" & $z.im & "j"
    

This is what Python and tools such as Matlab do.

Additionally it would be great if it were possible to use the same sort of 
representation in complex literals, e.g.: 
    
    
    var a = 1.0+2.2j
    

. 

Reply via email to