Skip to content

Instantly share code, notes, and snippets.

@erica
Created November 16, 2017 22:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/ee06008202c9fed699bfa6254c42c721 to your computer and use it in GitHub Desktop.
Save erica/ee06008202c9fed699bfa6254c42c721 to your computer and use it in GitHub Desktop.
// Angle+Trig.swift
// SwiftPlaneGeometry
#if os(Linux)
/// #error No Linux Support
#else
import Darwin
#endif
extension Angle {
/// Returns sine
public var sin: Double { return Darwin.sin(radians) }
/// Returns cosine
public var cos: Double { return Darwin.cos(radians) }
/// Returns tangent
public var tan: Double { return Darwin.tan(radians) }
/// Returns hyperbolic sine
public var sinh: Double { return Darwin.sinh(radians) }
/// Returns hyperbolic cosine
public var cosh: Double { return Darwin.cosh(radians) }
/// Returns hyperbolic tangent
public var tanh: Double { return Darwin.tanh(radians) }
/// Returns cosecant
public var csc: Double { return 1 / sin }
/// Returns secant
public var sec: Double { return 1 / cos }
/// Returns cotangent
public var cot: Double { return 1 / tan }
}
extension Double {
/// Returns angle corresponding to arcsin
public var asin: Angle { return Angle(radians: Darwin.asin(self)) }
/// Returns angle corresponding to arccos
public var acos: Angle { return Angle(radians: Darwin.acos(self)) }
/// Returns angle corresponding to arctan
public var atan: Angle { return Angle(radians: Darwin.atan(self)) }
/// Returns angle corresponding to inverse hyperbolic sine function
public var asinh: Angle { return Angle(radians: Darwin.asinh(self)) }
/// Returns angle corresponding to inverse hyperbolic cos function
public var acosh: Angle { return Angle(radians: Darwin.acosh(self)) }
/// Returns angle corresponding to inverse hyperbolic tan function
public var atanh: Angle { return Angle(radians: Darwin.atanh(self)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment