//===--- 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 FloatingPoint : 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 } @available(*, unavailable, renamed="FloatingPoint") public typealias FloatingPointType = FloatingPoint