0001    // Exponential.swift
0002    //
0003    // Copyright (c) 2014–2015 Mattt Thompson (http://mattt.me)
0004    //
0005    // Permission is hereby granted, free of charge, to any person obtaining a copy
0006    // of this software and associated documentation files (the "Software"), to deal
0007    // in the Software without restriction, including without limitation the rights
0008    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0009    // copies of the Software, and to permit persons to whom the Software is
0010    // furnished to do so, subject to the following conditions:
0011    //
0012    // The above copyright notice and this permission notice shall be included in
0013    // all copies or substantial portions of the Software.
0014    //
0015    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0018    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0020    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0021    // THE SOFTWARE.
0022    
0023    import Accelerate
0024    
0025    // MARK: Exponentiation
0026    
0027    public func exp(x: [Float]) -> [Float] {
0028        var results = [Float](count: x.count, repeatedValue: 0.0)
0029        vvexpf(&results, x, [Int32(x.count)])
0030    
0031        return results
0032    }
0033    
0034    public func exp(x: [Double]) -> [Double] {
0035        var results = [Double](count: x.count, repeatedValue: 0.0)
0036        vvexp(&results, x, [Int32(x.count)])
0037    
0038        return results
0039    }
0040    
0041    // MARK: Square Exponentiation
0042    
0043    public func exp2(x: [Float]) -> [Float] {
0044        var results = [Float](count: x.count, repeatedValue: 0.0)
0045        vvexp2f(&results, x, [Int32(x.count)])
0046    
0047        return results
0048    }
0049    
0050    public func exp2(x: [Double]) -> [Double] {
0051        var results = [Double](count: x.count, repeatedValue: 0.0)
0052        vvexp2(&results, x, [Int32(x.count)])
0053    
0054        return results
0055    }
0056    
0057    // MARK: Natural Logarithm
0058    
0059    public func log(x: [Float]) -> [Float] {
0060        var results = [Float](x)
0061        vvlogf(&results, x, [Int32(x.count)])
0062    
0063        return results
0064    }
0065    
0066    public func log(x: [Double]) -> [Double] {
0067        var results = [Double](x)
0068        vvlog(&results, x, [Int32(x.count)])
0069    
0070        return results
0071    }
0072    
0073    // MARK: Base-2 Logarithm
0074    
0075    public func log2(x: [Float]) -> [Float] {
0076        var results = [Float](x)
0077        vvlog2f(&results, x, [Int32(x.count)])
0078    
0079        return results
0080    }
0081    
0082    public func log2(x: [Double]) -> [Double] {
0083        var results = [Double](x)
0084        vvlog2(&results, x, [Int32(x.count)])
0085    
0086        return results
0087    }
0088    
0089    // MARK: Base-10 Logarithm
0090    
0091    public func log10(x: [Float]) -> [Float] {
0092        var results = [Float](x)
0093        vvlog10f(&results, x, [Int32(x.count)])
0094    
0095        return results
0096    }
0097    
0098    public func log10(x: [Double]) -> [Double] {
0099        var results = [Double](x)
0100        vvlog10(&results, x, [Int32(x.count)])
0101    
0102        return results
0103    }
0104    
0105    // MARK: Logarithmic Exponentiation
0106    
0107    public func logb(x: [Float]) -> [Float] {
0108        var results = [Float](x)
0109        vvlogbf(&results, x, [Int32(x.count)])
0110    
0111        return results
0112    }
0113    
0114    public func logb(x: [Double]) -> [Double] {
0115        var results = [Double](x)
0116        vvlogb(&results, x, [Int32(x.count)])
0117    
0118        return results
0119    }
0120