[swift-evolution] Proposal: floating point static min / max properties

Stephen Canon scanon at apple.com
Sat Dec 5 11:41:16 CST 2015

Hi Matthew —

This is something that we’ve discussed quite a bit internally, and are close to consensus on.  Many people feel that “max” and “min” are confusing or misleading, as they are not actually the largest / smallest values of the type, so the plan is to use much more explicit names (you can see an early sketch of this in test/Prototypes/FloatingPoint.swift, though there are a number of things that will be changed as well).  I’ve excerpted the relevant section here for convenience:

  /// Positive infinity.
  /// Compares greater than all finite numbers.
  static var infinity: Self { get }
  /// The greatest finite value.
  /// Compares greater than or equal to all finite numbers, but less than
  /// infinity.
  static var greatestFiniteMagnitude: Self { get }
  /// The least positive normal value.
  /// Compares less than or equal to all positive normal numbers.  There may
  /// be smaller positive numbers, but they are "subnormal", meaning that
  /// they are represented with less precision than normal numbers.
  static var leastNormalMagnitude: Self { get }
  /// The least positive value.
  /// Compares less than or equal to all positive numbers, but greater than
  /// zero.  If the target supports subnormal values, this is smaller than
  /// `leastNormalMagnitude`; otherwise they are equal.
  static var leastMagnitude: Self { get }

– Steve

> On Dec 5, 2015, at 11:10 AM, Matthew Johnson <matthew at anandabits.com> wrote:
> In the spirit of small commits and incremental change I have a very small proposal.  I am not sure if this belongs on the list or if small changes like this are ok as pull requests, but am starting here because it involves adding public API in the standard library.  
> Integer types have static min / max properties, but floating point types currently do not.  The Darwin implementation is very straightforward.  
> import Darwin
> public extension Float {
>   static let min = -FLT_MAX
>   static let max = FLT_MAX
> }
> public extension Double {
>   static let min = -DBL_MAX
>   static let max = DBL_MAX
> }
> Is there interest in adding this?  If so, what is the right way to proceed?
> Matthew
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151205/c979acfe/attachment.html>

More information about the swift-evolution mailing list