@@ -254,6 +254,28 @@ extension Quaternion {
254
254
public var isPure : Bool {
255
255
real. isZero
256
256
}
257
+
258
+ /// A "canonical" representation of the value.
259
+ ///
260
+ /// For normal quaternion instances with a RealType conforming to
261
+ /// BinaryFloatingPoint (the common case), the result is simply this value
262
+ /// unmodified. For zeros, the result has the representation (+0, +0, +0, +0).
263
+ /// For infinite values, the result has the representation (+inf, +0, +0, +0).
264
+ ///
265
+ /// If the RealType admits non-canonical representations, the x, y, z and r
266
+ /// components are canonicalized in the result.
267
+ ///
268
+ /// This is mainly useful for interoperation with other languages, where
269
+ /// you may want to reduce each equivalence class to a single representative
270
+ /// before passing across language boundaries, but it may also be useful
271
+ /// for some serialization tasks. It's also a useful implementation detail for
272
+ /// some primitive operations.
273
+ @_transparent
274
+ public var canonicalized : Self {
275
+ guard !isZero else { return . zero }
276
+ guard isFinite else { return . infinity }
277
+ return self . multiplied ( by: 1 )
278
+ }
257
279
}
258
280
259
281
// MARK: - Additional Initializers
0 commit comments