@@ -209,6 +209,23 @@ final class ElementaryFunctionTests: XCTestCase {
209209 }
210210 }
211211
212+ func testLog< T: Real & FixedWidthFloatingPoint & SIMDScalar > ( _ type: T . Type ) {
213+ // log(0) = undefined/infinity
214+ XCTAssertFalse ( Quaternion < T > . log ( Quaternion ( real: 0 , imaginary: 0 , 0 , 0 ) ) . isFinite)
215+ XCTAssertFalse ( Quaternion < T > . log ( Quaternion ( real: - 0 , imaginary: 0 , 0 , 0 ) ) . isFinite)
216+ XCTAssertFalse ( Quaternion < T > . log ( Quaternion ( real: - 0 , imaginary: - 0 , - 0 , - 0 ) ) . isFinite)
217+ XCTAssertFalse ( Quaternion < T > . log ( Quaternion ( real: 0 , imaginary: - 0 , - 0 , - 0 ) ) . isFinite)
218+
219+ var g = SystemRandomNumberGenerator ( )
220+ let values : [ Quaternion < T > ] = ( 0 ..< 100 ) . map { _ in
221+ Quaternion (
222+ real: T . random ( in: - 1 ... 1 , using: & g) ,
223+ imaginary: SIMD3 ( repeating: T . random ( in: - . pi ... . pi, using: & g) / 3 ) )
224+ }
225+ for q in values {
226+ XCTAssertTrue ( q. isApproximatelyEqual ( to: . log( . exp( q) ) ) )
227+ }
228+ }
212229
213230 func testCos< T: Real & FixedWidthFloatingPoint & SIMDScalar > ( _ type: T . Type ) {
214231 var g = SystemRandomNumberGenerator ( )
@@ -266,6 +283,8 @@ final class ElementaryFunctionTests: XCTestCase {
266283 testSinh ( Float32 . self)
267284 testCos ( Float32 . self)
268285 testSin ( Float32 . self)
286+
287+ testLog ( Float32 . self)
269288 }
270289
271290 func testDouble( ) {
@@ -275,5 +294,7 @@ final class ElementaryFunctionTests: XCTestCase {
275294 testSinh ( Float64 . self)
276295 testCos ( Float64 . self)
277296 testSin ( Float64 . self)
297+
298+ testLog ( Float64 . self)
278299 }
279300}
0 commit comments