[swift-evolution] [Re-Review] SE-0104: Protocol-oriented integers
plx
plxswift at icloud.com
Thu Feb 23 11:45:33 CST 2017
> On Feb 23, 2017, at 11:31 AM, David Sweeris <davesweeris at mac.com> wrote:
>
>
> On Feb 23, 2017, at 07:33, plx via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> Next quibble: `Magnitude` being defined as the “absolute value” of the underlying type seems a bit nonsensical if e.g. `Number` is intended to be adoptable by complex numbers (let alone quaternions, matrices, and whatnot). What *would* a conforming complex # implementation be expected to return as e.g. `(1-i).magnitude`?
>
> sqrt(2), I believe, or as close to it as can be represented by `Magnitude`
…which is what I’d expect if `x.magnitude` is supposed to be `||x||` or whatnot, but the stated motivation is:
/// The magnitude of this value.
///
/// For any numeric value `x`, `x.magnitude` is the absolute value of `x`.
/// You can use the `magnitude` property in operations that are simpler to
/// implement in terms of unsigned values, such as printing the value of an
/// integer, which is just printing a '-' character in front of an absolute
/// value.
///
/// let x = -200
/// // x.magnitude == 200
…for which uses the norm is not really helpful (and `Magnitude` not being `Comparable` is pretty annoying if it’s intended to be a norm; it really seems only intended to work as a generic tool for writing pretty-printers).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170223/ef33fae4/attachment.html>
More information about the swift-evolution
mailing list