Files
swift-mirror/stdlib/core/FloatingPointOperations.swift.gyb
David Farler 87c3d7421f Refine static func and var syntax
rdar://problem/17198298

- Allow 'static' in protocol property and func requirements, but not 'class'.
- Allow 'static' methods in classes - they are 'class final'.
- Only allow 'class' methods in classes (or extensions of classes)
- Remove now unneeded diagnostics related to finding 'static' in previously banned places.
- Update relevant diagnostics to make the new rules clear.

Swift SVN r24260
2015-01-08 03:03:29 +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
static 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.
static var infinity: Self { get }
/// A quiet NaN.
static var NaN: Self { get }
/// A quiet NaN.
static 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
/// @}
}