@@ -270,12 +270,41 @@ extension Quaternion {
270
270
/// before passing across language boundaries, but it may also be useful
271
271
/// for some serialization tasks. It's also a useful implementation detail for
272
272
/// some primitive operations.
273
+ ///
274
+ /// See also:
275
+ /// -
276
+ /// - `.transformCanonicalized`
273
277
@_transparent
274
278
public var canonicalized : Self {
275
279
guard !isZero else { return . zero }
276
280
guard isFinite else { return . infinity }
277
281
return self . multiplied ( by: 1 )
278
282
}
283
+
284
+ /// A "canonical transformation" representation of the value.
285
+ ///
286
+ /// For normal quaternion instances with a RealType conforming to
287
+ /// BinaryFloatingPoint (the common case) and a non-negative real component,
288
+ /// the result is simply this value unmodified. For instances with a negative
289
+ /// real component, the result is a quaternion with a positive real component
290
+ /// of equal magnitude and an unmodified imaginary compontent (-r, x, y, z).
291
+ /// For zeros, the result has the representation (+0, +0, +0, +0). For
292
+ /// infinite values, the result has the representation (+inf, +0, +0, +0).
293
+ ///
294
+ /// If the RealType admits non-canonical representations, the x, y, z and r
295
+ /// components are canonicalized in the result.
296
+ ///
297
+ /// See also:
298
+ /// -
299
+ /// - `.canonicalized`
300
+ @_transparent
301
+ public var transformCanonicalized : Self {
302
+ var canonical = canonicalized
303
+ if canonical. real. sign == . plus { return canonical }
304
+ // Clear the signbit of real even for -0
305
+ canonical. real. negate ( )
306
+ return canonical
307
+ }
279
308
}
280
309
281
310
// MARK: - Additional Initializers
0 commit comments