/**
向上取整
ceil(4.1) = 5.0
ceil(4.9) = 5.0
*/
public func ceil(_: Double) -> Double
/**
向下取整
floor(4.1) = 4.0
floor(4.9) = 4.0
*/
public func floor(_: Double) -> Double
/**
最接近參數(shù)的整數(shù) (如果有兩個就取偶數(shù))
nearbyint(-6.5) = -6
nearbyint(-5.5) = -6
nearbyint(-4.5) = -4
nearbyint(6.5) = 6
nearbyint(5.5) = 6
nearbyint(4.5) = 4
*/
public func nearbyint(_: Double) -> Double
/**
最接近參數(shù)的整數(shù) (如果有兩個就取偶數(shù))
rint(6.5) = 6.0
rint(5.5) = 6.0
rint(4.5) = 4.0
rint(-6.5) = -6.0
rint(-5.5) = -6.0
rint(-4.5) = -4.0
rint(5.112) = 5.0
*/
public func rint(_: Double) -> Double
/**
和rint一樣的等浊,不過返回的是Int
*/
public func lrint(_: Double) -> Int
/**
(其實就是四舍五入可婶,只不過負數(shù)的情況是反過來的) (似乎這就是正常的四舍五入)
> 0 滿0.5 + 1
< 0 滿0.5 - 1
*/
round(-6.5) = -7
round(-5.5) = -6
round(-4.5) = -5
round(6.5) = 7
round(5.5) = 6
round(4.5) = 5
public func round(_: Double) -> Double
/**
和round一樣挖腰,只不過返回的是整數(shù)
*/
public func lround(_: Double) -> Int
/**
直接去除數(shù)字的小數(shù)部分
*/
trunc(-6.534) = -6
trunc(4.34) = 4
public func trunc(_: Double) -> Double
/**
取模
*/
fmod(6, 2.1) = 1.8
fmod(0.6, 0.13) = 0.08
public func fmod(_: Double, _: Double) -> Double
/**
取余 (正負取絕對值小的那個)
*/
remainder(6, 1.8) = 0.6
remainder(0.6, 0.13) = -0.05
public func remainder(_: Double, _: Double) -> Double
/**
取余 (正負取絕對值小的那個)
a為的是第一個數(shù)除以第二個數(shù) 四舍五入的值
*/
var a: Int32
remquo(20.1, 13, &a)// -5.9, a = 2
remquo(20.1, 14, &a)// -7.9, a = 1
public func remquo(_: Double, _: Double, _: UnsafeMutablePointer<Int32>!) -> Double
/**
以第二個參數(shù)的符號(正或負), 返回第一個參數(shù)
*/
copysign(1.0, -3.2)// -1.0
copysign(1.0, 2.4 )// 1.0
public func copysign(_: Double, _: Double) -> Double
/**
x = a - b <= 0 ? 0 : a - b
*/
public func fdim(a: Double, b: Double) -> Double
/**
x = a >= b ? a : b
*/
public func fmax(a: Double, b: Double) -> Double
/**
x = a <= b ? a : b
*/
public func fmin(a: Double, b: Double) -> Double
/**
x = a * b + c
*/
public func fma(a: Double, b: Double, c: Double) -> Double
/**
返回值為參數(shù)的小數(shù)部分
整數(shù)部分通過指針存
*/
eg:
var mech: Double = 0
let num = modf(3.123, &mech)
//mech = 3.0 num = 0.123
public func modf(_: Double, _: UnsafeMutablePointer<Double>!) -> Double
//x的y次冪
public func pow(x: Double, y: Double) -> Double
//平方根
public func sqrt(_: Double) -> Double
//絕對值
public func fabs(_: Double) -> Double
//立方根
public func cbrt(_: Double) -> Double
/**
x * (2的num次冪)
*/
eg:
ldexp(3.0, 3) = 24
ldexp(3.0, 2) = 12
public func ldexp(x: Double, num: Int32) -> Double
/**
m * 2^n = (輸入值)
*/
var n: Int32 = 0
var m = frexp(16.400000, &n)
n = 5 m = 0.5125
16.4 = 0.5125 * (2^5) = 0.5125 * 32
public func frexp(_: Double, _: UnsafeMutablePointer<Int32>!) -> Double
/**
直角三角形的斜邊長
a^2 + b^2 = c^2
已知a艘款,b 求c
*/
public func hypot(_: Double, _: Double) -> Double
/**
反三角函數(shù)
*/
public func acos(_: Double) -> Double
public func asin(_: Double) -> Double
public func atan(_: Double) -> Double
反正切 (主值)拜轨,結果介于[-PI/2,PI/2]
public func atan2(_: Double, _: Double) -> Double
反正切 (整圓值), 結果介于[-PI,PI]
/**
三角函數(shù)
*/
public func cos(_: Double) -> Double
public func sin(_: Double) -> Double
public func tan(_: Double) -> Double
/**
反雙曲三角函數(shù)
*/
public func acosh(_: Double) -> Double
public func asinh(_: Double) -> Double
public func atanh(_: Double) -> Double
/**
雙曲三角函數(shù)
*/
public func cosh(_: Double) -> Double
public func sinh(_: Double) -> Double
public func tanh(_: Double) -> Double
//e的n次冪
public func exp(_: Double) -> Double
//2的n次冪
public func exp2(_: Double) -> Double
//1.71828 的n次冪 (不知道這個數(shù)是干嘛的)
public func expm1(_: Double) -> Double
//e為底的對數(shù)
public func log(_: Double) -> Double
//10為底的對數(shù)
public func log10(_: Double) -> Double
//2為底的對數(shù)
public func log2(_: Double) -> Double