diff --git a/Math/Math.xcodeproj/project.pbxproj b/Math/Math.xcodeproj/project.pbxproj index d2f4354..650bf7c 100644 --- a/Math/Math.xcodeproj/project.pbxproj +++ b/Math/Math.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ C005E00A1BE1CBA800F1BD3C /* MatrixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C005E0091BE1CBA800F1BD3C /* MatrixTests.swift */; }; C005E0391BE1CC7A00F1BD3C /* Matrix.swift in Sources */ = {isa = PBXBuildFile; fileRef = C005E0381BE1CC7A00F1BD3C /* Matrix.swift */; }; C04449C11BE26A0700ABF046 /* Vector.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04449C01BE26A0700ABF046 /* Vector.swift */; }; + C08C72021BED07BB0030AD52 /* MatrixFunctionalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */; }; + C08C72041BED08900030AD52 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C72031BED08900030AD52 /* Types.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -33,6 +35,8 @@ C005E00B1BE1CBA800F1BD3C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C005E0381BE1CC7A00F1BD3C /* Matrix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matrix.swift; sourceTree = ""; }; C04449C01BE26A0700ABF046 /* Vector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vector.swift; sourceTree = ""; }; + C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatrixFunctionalTests.swift; sourceTree = ""; }; + C08C72031BED08900030AD52 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -78,6 +82,7 @@ C005DFFD1BE1CBA700F1BD3C /* Math.h */, C005E0381BE1CC7A00F1BD3C /* Matrix.swift */, C04449C01BE26A0700ABF046 /* Vector.swift */, + C08C72031BED08900030AD52 /* Types.swift */, C005DFFF1BE1CBA700F1BD3C /* Info.plist */, ); path = Math; @@ -87,6 +92,7 @@ isa = PBXGroup; children = ( C005E0091BE1CBA800F1BD3C /* MatrixTests.swift */, + C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */, C005E00B1BE1CBA800F1BD3C /* Info.plist */, ); path = MathTests; @@ -200,6 +206,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C08C72041BED08900030AD52 /* Types.swift in Sources */, C04449C11BE26A0700ABF046 /* Vector.swift in Sources */, C005E0391BE1CC7A00F1BD3C /* Matrix.swift in Sources */, ); @@ -210,6 +217,7 @@ buildActionMask = 2147483647; files = ( C005E00A1BE1CBA800F1BD3C /* MatrixTests.swift in Sources */, + C08C72021BED07BB0030AD52 /* MatrixFunctionalTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Math/Math/Types.swift b/Math/Math/Types.swift new file mode 100644 index 0000000..374e300 --- /dev/null +++ b/Math/Math/Types.swift @@ -0,0 +1,27 @@ +// +// Types.swift +// Math +// +// Created by Eryn Wells on 11/6/15. +// Copyright © 2015 Eryn Wells. All rights reserved. +// + +import Foundation + +public typealias Float = Swift.Float + +/** Acceptable tolerance for Float equality. */ +let Epsilon: Float = 1e-6 + +extension Float { + /** Test that `other` is almost equal (i.e. within the +/- Epsilon) to `self`. */ + func almostEqual(other: Float) -> Bool { + return other >= (self - Epsilon) && other <= (self + Epsilon) + } +} + +/** Custom operator for almost-equality of floats. */ +infix operator =~ { associativity left precedence 130 } +public func =~(lhs: Float, rhs: Float) -> Bool { + return lhs.almostEqual(rhs) +} \ No newline at end of file