Files
swift-mirror/stdlib/public/core/FloatingPointOperations.swift.gyb
gregomni e2dee6b9dd [stdlib] Switch keywords from 'typealias' to 'associatedtype' in stdlib
Fixes deprecation warnings arising from addition of new
‘associatedtype’ keyword in sr-511.
2016-01-14 09:39:15 -08:00

99 lines
2.5 KiB
Swift

//===--- FloatingPointOperations.swift.gyb --------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 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 all_integer_types
# 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
}
/// A set of common requirements for Swift's floating point types.
public protocol FloatingPointType : Strideable {
associatedtype _BitsType
@warn_unused_result
static func _fromBitPattern(bits: _BitsType) -> Self
@warn_unused_result
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
}