negate
Replaces this value with its additive inverse.
override mutating func negate()
The result is always exact. This example uses the negate()
method to negate the value of the variable x
:
var x = 21.5
x.negate()
// x == -21.5
Replaces this value with its additive inverse.
override mutating func negate()
The result is always exact. This example uses the negate()
method to negate the value of the variable x
:
var x = 21.5
x.negate()
// x == -21.5
import Swift
protocol FloatingPoint : Hashable, SignedNumeric, Strideable where Self == Self.Magnitude
A floating-point numeric type.
mutating func negate()
Replaces this value with its additive inverse.
associatedtype Exponent : SignedInteger
A type that can represent any written exponent.
init(_ value: Int)
Creates a new value, rounded to the closest possible representation.
init<Source>(_ value: Source) where Source : BinaryInteger
Creates a new value, rounded to the closest possible representation.
init?<Source>(exactly value: Source) where Source : BinaryInteger
Creates a new value, if the given integer can be represented exactly.
init(sign: FloatingPointSign, exponent: Self.Exponent, significand: Self)
Creates a new value from the given sign, exponent, and significand.
init(signOf: Self, magnitudeOf: Self)
Creates a new floating-point value using the sign of one value and the magnitude of another.
static var greatestFiniteMagnitude: Self { get }
The greatest finite number representable by this type.
static var infinity: Self { get }
Positive infinity.
static var leastNonzeroMagnitude: Self { get }
The least positive number.
static var leastNormalMagnitude: Self { get }
The least positive normal number.
static var nan: Self { get }
A quiet NaN (“not a number”).
static var pi: Self { get }
The mathematical constant pi (π), approximately equal to 3.14159.
static var radix: Int { get }
The radix, or base of exponentiation, for a floating-point type.
static var signalingNaN: Self { get }
A signaling NaN (“not a number”).
static var ulpOfOne: Self { get }
The unit in the last place of 1.0.
static func maximum(_ x: Self, _ y: Self) -> Self
Returns the greater of the two given values.
static func maximumMagnitude(_ x: Self, _ y: Self) -> Self
Returns the value with greater magnitude.
static func minimum(_ x: Self, _ y: Self) -> Self
Returns the lesser of the two given values.
static func minimumMagnitude(_ x: Self, _ y: Self) -> Self
Returns the value with lesser magnitude.
var exponent: Self.Exponent { get }
The exponent of the floating-point value.
var floatingPointClass: FloatingPointClassification { get }
The classification of this value.
var isCanonical: Bool { get }
A Boolean value indicating whether the instance’s representation is in its canonical form.
var isFinite: Bool { get }
A Boolean value indicating whether this instance is finite.
var isInfinite: Bool { get }
A Boolean value indicating whether the instance is infinite.
var isNaN: Bool { get }
A Boolean value indicating whether the instance is NaN (“not a number”).
var isNormal: Bool { get }
A Boolean value indicating whether this instance is normal.
var isSignalingNaN: Bool { get }
A Boolean value indicating whether the instance is a signaling NaN.
var isSubnormal: Bool { get }
A Boolean value indicating whether the instance is subnormal.
var isZero: Bool { get }
A Boolean value indicating whether the instance is equal to zero.
var nextDown: Self { get }
The greatest representable value that compares less than this value.
var nextUp: Self { get }
The least representable value that compares greater than this value.
var sign: FloatingPointSign { get }
The sign of the floating-point value.
var significand: Self { get }
The significand of the floating-point value.
var ulp: Self { get }
The unit in the last place of this value.
override static func * (lhs: Self, rhs: Self) -> Self
Multiplies two values and produces their product, rounding to a representable value.
override static func *= (lhs: inout Self, rhs: Self)
Multiplies two values and stores the result in the left-hand-side variable, rounding to a representable value.
override static func + (lhs: Self, rhs: Self) -> Self
Adds two values and produces their sum, rounded to a representable value.
override static func += (lhs: inout Self, rhs: Self)
Adds two values and stores the result in the left-hand-side variable, rounded to a representable value.
override static func - (operand: Self) -> Self
Calculates the additive inverse of a value.
override static func - (lhs: Self, rhs: Self) -> Self
Subtracts one value from another and produces their difference, rounded to a representable value.
override static func -= (lhs: inout Self, rhs: Self)
Subtracts the second value from the first and stores the difference in the left-hand-side variable, rounding to a representable value.
static func / (lhs: Self, rhs: Self) -> Self
Returns the quotient of dividing the first value by the second, rounded to a representable value.
static func /= (lhs: inout Self, rhs: Self)
Divides the first value by the second and stores the quotient in the left-hand-side variable, rounding to a representable value.
mutating func addProduct(_ lhs: Self, _ rhs: Self)
Adds the product of the two given values to this value in place, computed without intermediate rounding.
func addingProduct(_ lhs: Self, _ rhs: Self) -> Self
Returns the result of adding the product of the two given values to this value, computed without intermediate rounding.
mutating func formRemainder(dividingBy other: Self)
Replaces this value with the remainder of itself divided by the given value.
mutating func formSquareRoot()
Replaces this value with its square root, rounded to a representable value.
mutating func formTruncatingRemainder(dividingBy other: Self)
Replaces this value with the remainder of itself divided by the given value using truncating division.
func isEqual(to other: Self) -> Bool
Returns a Boolean value indicating whether this instance is equal to the given value.
func isLess(than other: Self) -> Bool
Returns a Boolean value indicating whether this instance is less than the given value.
func isLessThanOrEqualTo(_ other: Self) -> Bool
Returns a Boolean value indicating whether this instance is less than or equal to the given value.
func isTotallyOrdered(belowOrEqualTo other: Self) -> Bool
Returns a Boolean value indicating whether this instance should precede or tie positions with the given value in an ascending sort.
func remainder(dividingBy other: Self) -> Self
Returns the remainder of this value divided by the given value.
mutating func round(_ rule: FloatingPointRoundingRule)
Rounds the value to an integral value using the specified rounding rule.
func rounded(_ rule: FloatingPointRoundingRule) -> Self
Returns this value rounded to an integral value using the specified rounding rule.
func squareRoot() -> Self
Returns the square root of the value, rounded to a representable value.
func truncatingRemainder(dividingBy other: Self) -> Self
Returns the remainder of this value divided by the given value using truncating division.