Files
swift-mirror/stdlib/core/FloatingPointOperations.swift.gyb
Dave Abrahams 7c9ebaa19f [stdlib] Propagate LiteralConvertible docs
219 undocumented public APIs remain in core

Swift SVN r22213
2014-09-23 11:12:39 +00:00

118 lines
3.0 KiB
Swift

//===--- FloatingPointOperations.swift.gyb --------------------*- 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
//
//===----------------------------------------------------------------------===//
%{
from SwiftIntTypes import *
# Number of bits in the Builtin.Word type
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
}%
/// The set of possible IEEE 754 "classes"
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
}
}
/// A set of common requirements for Swift's floating point types.
public protocol FloatingPointType : Strideable {
typealias _BitsType
class func _fromBitPattern(bits: _BitsType) -> Self
func _toBitPattern() -> _BitsType
% for src_ty in all_integer_types(word_bits):
/// Create an instance initialized to `value`.
init(_ value: ${src_ty.stdlib_name})
% end
/// 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.
/// The IEEE 754 "class" of this type.
var floatingPointClass: FloatingPointClassification { get }
/// `true` iff `self` is negative
var isSignMinus: Bool { get }
/// `true` iff `self` is normal (not zero, subnormal, infinity, or
/// NaN).
var isNormal: Bool { get }
/// `true` iff `self` is zero, subnormal, or normal (not infinity
/// or NaN).
var isFinite: Bool { get }
/// `true` iff `self` is +0.0 or -0.0.
var isZero: Bool { get }
/// `true` iff `self` is subnormal.
var isSubnormal: Bool { get }
/// `true` iff `self` is infinity.
var isInfinite: Bool { get }
/// `true` iff `self` is NaN.
var isNaN: Bool { get }
/// `true` iff `self` 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
/// @}
}