[swift-evolution] [Proposal] Add floor() and ceiling() functions to FloatingPoint

Stephen Canon scanon at apple.com
Fri Jul 1 10:38:50 CDT 2016

These are already included with SE-0067, we’re just working on finishing up the implementation.

  /// Remainder of `self` divided by `other`.  This is the IEEE 754 remainder
  /// operation.
  /// For finite `self` and `other`, the remainder `r` is defined by
  /// `r = self - other*n`, where `n` is the integer nearest to `self/other`.
  /// (Note that `n` is *not* `self/other` computed in floating-point
  /// arithmetic, and that `n` may not even be representable in any available
  /// integer type).  If `self/other` is exactly halfway between two integers,
  /// `n` is chosen to be even.
  /// It follows that if `self` and `other` are finite numbers, the remainder
  /// `r` satisfies `-|other|/2 <= r` and `r <= |other|/2`.
  /// `remainder` is always exact.
  func remainder(dividingBy other: Self) -> Self

  /// Mutating form of `remainder`.
  mutating func formRemainder(dividingBy other: Self)

  /// Remainder of `self` divided by `other` using truncating division.
  /// Equivalent to the C standard library function `fmod`.
  /// If `self` and `other` are finite numbers, the truncating remainder
  /// `r` has the same sign as `other` and is strictly smaller in magnitude.
  /// It satisfies `r = self - other*n`, where `n` is the integral part
  /// of `self/other`.
  /// `truncatingRemainder` is always exact.
  func truncatingRemainder(dividingBy other: Self) -> Self

  /// Mutating form of `truncatingRemainder`.
  mutating func formTruncatingRemainder(dividingBy other: Self)

  /// Square root of `self`.
  func squareRoot() -> Self

  /// Mutating form of square root.
  mutating func formSquareRoot()

  /// `self + lhs*rhs` computed without intermediate rounding.  Implements the
  /// IEEE 754 `fusedMultiplyAdd` operation.
  func addingProduct(_ lhs: Self, _ rhs: Self) -> Self

  /// Fused multiply-add, accumulating the product of `lhs` and `rhs` to `self`.
  mutating func addProduct(_ lhs: Self, _ rhs: Self)

> On Jul 1, 2016, at 4:06 AM, Björn Forster via swift-evolution <swift-evolution at swift.org> wrote:
> Hello Karl and everyone else involved,
> an IEEE754 conform floating point implementation requires also squrt and a remainer function being provided by the respective float implementation. Shouldn't these two be also added to the FloatingPoint protocol now that the rounding functions are being added?
> Kind Regards,
> Björn  
> _______________________________________________
> 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/20160701/5e843d1f/attachment.html>

More information about the swift-evolution mailing list