Files
swift-mirror/stdlib/core/FloatingPointOperations.swift
Jordan Rose cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00

101 lines
2.8 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@public enum FloatingPointClassification {
case SignalingNaN
case QuietNaN
case NegativeInfinity
case NegativeNormal
case NegativeSubnormal
case NegativeZero
case PositiveZero
case PositiveSubnormal
case PositiveNormal
case PositiveInfinity
}
extension FloatingPointClassification : Equatable {}
@public
func ==(lhs: FloatingPointClassification, rhs: FloatingPointClassification) -> Bool {
switch (lhs, rhs) {
case (.SignalingNaN, .SignalingNaN),
(.QuietNaN, .QuietNaN),
(.NegativeInfinity, .NegativeInfinity),
(.NegativeNormal, .NegativeNormal),
(.NegativeSubnormal, .NegativeSubnormal),
(.NegativeZero, .NegativeZero),
(.PositiveZero, .PositiveZero),
(.PositiveSubnormal, .PositiveSubnormal),
(.PositiveNormal, .PositiveNormal),
(.PositiveInfinity, .PositiveInfinity):
return true
default:
return false
}
}
@public protocol FloatingPointNumber {
typealias _BitsType
class func _fromBitPattern(bits: _BitsType) -> Self
func _toBitPattern() -> _BitsType
/// The positive infinity.
class var infinity: Self { get }
/// A quiet NaN.
class var NaN: Self { get }
/// A quiet NaN.
class var quietNaN: Self { get }
/// @{
/// IEEE 754-2008 Non-computational operations.
// IEEE 754 calls this 'class', but this name is a keyword, and is too
// general.
var floatingPointClass: FloatingPointClassification { get }
/// Returns true if this number has a negative sign.
var isSignMinus: Bool { get }
/// Returns true if this number is normal (not zero, subnormal, infinity, or
/// NaN).
var isNormal: Bool { get }
/// Returns true if this number is zero, subnormal, or normal (not infinity
/// or NaN).
var isFinite: Bool { get }
/// Returns true if this number is +0.0 or -0.0.
var isZero: Bool { get }
/// Returns true if this number is subnormal.
var isSubnormal: Bool { get }
/// Returns true if this number is infinity.
var isInfinite: Bool { get }
/// Returns true if this number is NaN.
var isNaN: Bool { get }
/// Returns true if this number is a signaling NaN.
var isSignaling: Bool { get }
// Not implemented, because it only makes sense for decimal floating point.
// Binary floating point numbers are always canonical.
// func isCanonical() -> Bool
/// @}
}