Created
June 27, 2014 18:54
-
-
Save seivan/b0a281c6d7f4a75d50de to your computer and use it in GitHub Desktop.
I can't believe this actually worked O_o
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ScalarArithmetic { | |
var acos:Self {get} | |
var asin:Self {get} | |
var atan:Self {get} | |
func atan2(x:Self) -> Self | |
var cos:Self {get} | |
var sin:Self {get} | |
var tan:Self {get} | |
var exp:Self {get} | |
var exp2:Self {get} | |
var log:Self {get} | |
var log10:Self {get} | |
var log2:Self {get} | |
func pow(exponent:Self) -> Self | |
var sqrt:Self {get} | |
} | |
extension Double : ScalarArithmetic { | |
var abs:Double { return Double.abs(self) } | |
var acos:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.acos(self) | |
#else | |
return Darwin.acos(self) | |
#endif | |
} | |
var asin:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.asin(self) | |
#else | |
return Darwin.asin(self) | |
#endif | |
} | |
var atan:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.atan(self) | |
#else | |
return Darwin.atan(self) | |
#endif | |
} | |
func atan2(x:Double) -> Double { | |
return 0 | |
} | |
var cos:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.cos(self) | |
#else | |
return Darwin.cos(self) | |
#endif | |
} | |
var sin:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.sin(self) | |
#else | |
return Darwin.sin(self) | |
#endif | |
} | |
var tan:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.tan(self) | |
#else | |
return Darwin.tan(self) | |
#endif | |
} | |
var exp:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.exp(self) | |
#else | |
return Darwin.exp(self) | |
#endif | |
} | |
var exp2:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.exp2(self) | |
#else | |
return Darwin.exp2(self) | |
#endif | |
} | |
var log:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.log(self) | |
#else | |
return Darwin.log(self) | |
#endif | |
} | |
var log10:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.log10(self) | |
#else | |
return Darwin.log10(self) | |
#endif | |
} | |
var log2:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.log2(self) | |
#else | |
return Darwin.log2(self) | |
#endif | |
} | |
func pow(exponent:Double) -> Double { | |
return 0 | |
} | |
var sqrt:Double { | |
#if !(arch(x86_64) || arch(arm64)) | |
return Darwin.sqrt(self) | |
#else | |
return Darwin.sqrt(self) | |
#endif | |
} | |
} | |
#if !(arch(x86_64) || arch(arm64)) | |
protocol ScalarOperatable { | |
var toDouble:Double { get } | |
} | |
extension Int : ScalarOperatable { | |
var toDouble:Double { return Double(self) } | |
} | |
extension Float : ScalarOperatable { | |
var toDouble:Double { return Double(self) } | |
} | |
// extension CGFloat : ScalarOperatable { | |
// var toDouble:Double { return Double(self) } | |
// } | |
@infix func == <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs.toDouble == rhs.toDouble) | |
} | |
@infix func != <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs == rhs) == false | |
} | |
@infix func <= <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs.toDouble <= rhs.toDouble) | |
} | |
@infix func < <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs.toDouble < rhs.toDouble) | |
} | |
@infix func >= <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs < rhs) == false | |
} | |
@infix func > <T:ScalarOperatable, U:ScalarOperatable> (lhs:T,rhs:U) -> Bool { | |
return (lhs <= rhs) == false | |
} | |
@infix func - <T:ScalarOperatable, U:ScalarOperatable>(lhs: T, rhs:U) -> Double { | |
return lhs.toDouble - rhs.toDouble | |
} | |
@assignment @infix func -= <U:ScalarOperatable>(inout lhs:Double, rhs:U) { | |
lhs = lhs - rhs.toDouble | |
} | |
@infix func + <T:ScalarOperatable, U:ScalarOperatable>(lhs: T, rhs:U) -> Double { | |
return lhs.toDouble + rhs.toDouble | |
} | |
@assignment @infix func += <U:ScalarOperatable>(inout lhs:Double, rhs:U) { | |
lhs = lhs + rhs.toDouble | |
} | |
@infix func * <T:ScalarOperatable, U:ScalarOperatable>(lhs: T, rhs:U) -> Double { | |
return lhs.toDouble * rhs.toDouble | |
} | |
@assignment @infix func *= <U:ScalarOperatable>(inout lhs:Double, rhs:U) { | |
lhs = lhs * rhs.toDouble | |
} | |
@infix func / <T:ScalarOperatable, U:ScalarOperatable>(lhs: T, rhs:U) -> Double { | |
return lhs.toDouble / rhs.toDouble | |
} | |
@assignment @infix func /= <U:ScalarOperatable>(inout lhs:Double, rhs:U) { | |
lhs = lhs / rhs.toDouble | |
} | |
extension CGPoint { | |
init(x:Double, y:Double) { | |
self.init(x:x, y:y) | |
} | |
} | |
extension CGSize { | |
init(width:Double, height:Double) { | |
self.init(width:width, height:height) | |
} | |
} | |
extension CGVector { | |
init(dx:Double, dy:Double) { | |
self.init(dx:dy, dy:dy) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment