apple / swift-numerics

Advanced mathematical types and functions for Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slight tweaks to Complex

CTMacUser opened this issue · comments

I just took a look at this project, and have some suggestions for slight tweaks.

  • magnitude should return RealType.magnitude instead of RealType.

  • IntegerLiteralType should alias to RealType’s version.

  • The Codable conditional conformance could be split into separate Encodable and Decodable conditional conformances.

  • The debugDescription could be unconditional.

      extension Complex: CustomDebugConvertible {
          public var debugDescription: String {
              String(describing: Self.self) + “(“ + String(reflecting: x) + “, “ + String(reflecting: y) + “)”
          }
      }
    

I just took a look at this project, and have some suggestions for slight tweaks.

  • magnitude should return RealType.magnitude instead of RealType.

As Susan noted, these types are always the same, so this is only a spelling change.

  • IntegerLiteralType should alias to RealType’s version.

I don't think that this actually changes anything with the way integer literals are currently implemented in the compiler, but I don't think that it hurts anything either.

  • The Codable conditional conformance could be split into separate Encodable and Decodable conditional conformances.

I'm not sure if this really gains us anything or not (I expect a Real type that only conforms to one of the two to be quite unusual), but it also doesn't cost anything, so sure.

  • The debugDescription could be unconditional.
      extension Complex: CustomDebugConvertible {
          public var debugDescription: String {
              String(describing: Self.self) + “(“ + String(reflecting: x) + “, “ + String(reflecting: y) + “)”
          }
      }
    

Sure.

@CTMacUser I think that all of the points raised here are resolved, OK to close this?

You're not planning to update IntegerLiteralType?

My sample had "String(describing: Self.self)" replacing "Complex<\(RealType.self)>" because I found out that when Swift prints out a type, and the type is generic, it'll include the generic arguments along with the base name.

You're not planning to update IntegerLiteralType?

This change has been made:

public typealias IntegerLiteralType = RealType.IntegerLiteralType