swift-numerics
swift-numerics copied to clipboard
Slight tweaks to Complex
I just took a look at this project, and have some suggestions for slight tweaks.
-
magnitude
should returnRealType.magnitude
instead ofRealType
. -
IntegerLiteralType
should alias toRealType
’s version. -
The
Codable
conditional conformance could be split into separateEncodable
andDecodable
conditional conformances. -
The
debugDescription
could be unconditional.extension Complex: CustomDebugConvertible { public var debugDescription: String { String(describing: Self.self) + “(“ + String(reflecting: x) + “, “ + String(reflecting: y) + “)” } }
It seems that RealType.Magnitude always equal to RealType
https://github.com/apple/swift/blob/f5f214de21b24627b9499a1581a64052f1235f09/stdlib/public/core/FloatingPoint.swift#L162
I just took a look at this project, and have some suggestions for slight tweaks.
magnitude
should returnRealType.magnitude
instead ofRealType
.
As Susan noted, these types are always the same, so this is only a spelling change.
IntegerLiteralType
should alias toRealType
’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 separateEncodable
andDecodable
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