File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change @@ -31,15 +31,10 @@ extension Quaternion/*: ElementaryFunctions */ {
31
31
/// `exp(r) cos(θ)` would not be).
32
32
public static func exp( _ q: Quaternion < RealType > ) -> Quaternion < RealType > {
33
33
guard q. isFinite else { return q }
34
- // Firstly evaluate θ and v/θ where θ = ||v|| (as discussed above)
35
- // There are 2 special cases for ||v|| that we need to take care of:
36
- // The value of ||v|| may be invalid due to an overflow in `.lengthSquared`.
37
- // As the internal `SIMD3.length` helper functions deals with overflow and
38
- // underflow of `.lengthSquared`, we can safely ignore this case here.
39
- // However, we still have to check for ||v|| = 0 before evaluating v/θ
40
- // as it would incorrectly yield a division by zero.
41
- let phase = q. imaginary. length
42
- let unitAxis = !phase. isZero ? ( q. imaginary / phase) : . zero
34
+ // For real quaternions we can skip phase and axis calculations
35
+ // TODO: Replace q.imaginary == .zero with `q.isReal`
36
+ let phase = q. imaginary == . zero ? . zero : q. imaginary. length
37
+ let unitAxis = q. imaginary == . zero ? . zero : ( q. imaginary / phase)
43
38
// If real < log(greatestFiniteMagnitude), then exp(q.real) does not overflow.
44
39
// To protect ourselves against sketchy log or exp implementations in
45
40
// an unknown host library, or slight rounding disagreements between
You can’t perform that action at this time.
0 commit comments