Skip to content

Commit

Permalink
Use Foundation versions of math functions (#6)
Browse files Browse the repository at this point in the history
* Use Foundation versions of math functions

If neither Darwin, nor Glibc are available, use Foundation to import
math functions.

Use dynamic library target on Windows since ar tool doesn't seem to
exist.

* Fix test_asinh() by adding accuracy parameter

* Reduce accuracy for testQuatFromEulerAngles_0_(n)90_0

* Remove WASM CI

* Use Swift 5.5 in on Windows CI

* Update Windows CI

* Update ci-windows.yml

* Update CI trigger

Co-authored-by: Christian Treffs <ctreffs@gmail.com>
  • Loading branch information
pcbeard and ctreffs authored Sep 22, 2021
1 parent 126cdc2 commit 65aa6b5
Show file tree
Hide file tree
Showing 38 changed files with 397 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
linux-test-build-release:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
macos-test-build-release-xcode:
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/ci-wasm.yml

This file was deleted.

61 changes: 35 additions & 26 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,43 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
windows-test-build-release:
runs-on: windows-latest
env:
SNAPSHOT: "https://swift.org/builds/swift-5.4.1-release/windows10/swift-5.4.1-RELEASE/swift-5.4.1-RELEASE-windows10.exe"
strategy:
matrix:
include:
- tag: 5.5-RELEASE
branch: swift-5.5-release
steps:
- uses: actions/checkout@master
- uses: seanmiddleditch/gha-setup-vsdevenv@master

- name: Install Swift
run: |
Install-Binary -Url "${env:SNAPSHOT}" -Name "installer.exe" -ArgumentList ("-q")
- name: Set Environment Variables
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Adjust Paths
run: |
echo "C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install Supporting Files
run: |
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
- name: Test
run: swift test -v --skip-update --parallel --enable-test-discovery
- name: Build Release
run: swift build -c release
- uses: actions/checkout@master
with:
fetch-depth: 1

- uses: seanmiddleditch/gha-setup-vsdevenv@master

- name: Install Swift ${{ matrix.tag }}
run: |
Install-Binary -Url "https://swift.org/builds/${{ matrix.branch }}/windows10/swift-${{ matrix.tag }}/swift-${{ matrix.tag }}-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")
- name: Set Environment Variables
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Adjust Paths
run: |
echo "C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install Supporting Files
run: |
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
- name: Test
run: swift test -v --skip-update --parallel --enable-test-discovery

- name: Build Release
run: swift build -c release
7 changes: 6 additions & 1 deletion .github/workflows/markdown-link-check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Check markdown links

on: push
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
markdown-link-check:
Expand Down
12 changes: 9 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ swiftSettings.append(.define("FRB_MATH_USE_SIMD"))

#if canImport(Darwin)
swiftSettings.append(.define("FRB_MATH_DARWIN"))
#elseif canImport(Glibc)
swiftSettings.append(.define("FRB_MATH_GLIBC"))
#elseif canImport(Foundation)
swiftSettings.append(.define("FRB_MATH_FOUNDATION"))
#endif

#if canImport(Glibc)
swiftSettings.append(.define("FRB_MATH_GLIBC"))
#if os(Windows)
let libraryType : Product.Library.LibraryType = .dynamic
#else
let libraryType : Product.Library.LibraryType = .static
#endif

let package = Package(
name: "FirebladeMath",
products: [
.library(
name: "FirebladeMath",
type: .static,
type: libraryType,
targets: ["FirebladeMath"])
],
targets: [
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![macOS](https://github.com/fireblade-engine/math/actions/workflows/ci-macos.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-macos.yml)
[![Linux](https://github.com/fireblade-engine/math/actions/workflows/ci-linux.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-linux.yml)
[![Windows](https://github.com/fireblade-engine/math/actions/workflows/ci-windows.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-windows.yml)
[![WASM](https://github.com/fireblade-engine/math/actions/workflows/ci-wasm.yml/badge.svg)](https://github.com/fireblade-engine/math/actions/workflows/ci-wasm.yml)
[![swift-version-compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/fireblade-engine/math)
[![platform-compatilibilty](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/fireblade-engine/math)
<!--[![platform-webassembly](https://img.shields.io/badge/Platform-WebAssembly-blue.svg)](https://github.com/swiftwasm/swift#swiftwasm)-->
Expand Down
8 changes: 8 additions & 0 deletions Sources/FirebladeMath/Functions/abs.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand Down Expand Up @@ -26,4 +30,8 @@ public func abs(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.fabs(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.fabs(double)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/acos.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -20,6 +24,10 @@ public func acos(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.acosf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.acosf(float)
#endif
}

/// Computes the principal value of the arc cosine of arg.
Expand All @@ -36,4 +44,8 @@ public func acos(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.acos(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.acos(double)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/acosh.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -20,6 +24,10 @@ public func acosh(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.acosh(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.acosh(double)
#endif
}

/// Computes the inverse hyperbolic cosine of arg.
Expand All @@ -36,4 +44,8 @@ public func acosh(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.acoshf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.acoshf(float)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/asin.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -20,6 +24,10 @@ public func asin(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.asin(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.asin(double)
#endif
}

/// Computes the principal values of the arc sine of arg.
Expand All @@ -36,4 +44,8 @@ public func asin(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.asinf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.asinf(float)
#endif
}
13 changes: 12 additions & 1 deletion Sources/FirebladeMath/Functions/asinh.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -20,6 +24,10 @@ public func asinh(_ double: Double) -> Double {

return Glibc.asinh(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.asinh(double)
#endif
}

/// Computes the inverse hyperbolic sine of arg.
Expand All @@ -33,7 +41,10 @@ public func asinh(_ float: Float) -> Float {
#endif

#if FRB_MATH_GLIBC

return Glibc.asinhf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.asinhf(float)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/atan.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -19,6 +23,10 @@ public func atan(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.atan(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atan(double)
#endif
}

/// Computes the principal value of the arc tangent of arg.
Expand All @@ -34,4 +42,8 @@ public func atan(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.atanf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atanf(float)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/atan2.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -18,6 +22,10 @@ public func atan2(_ y: Double, _ x: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.atan2(y, x)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atan2(y, x)
#endif
}

/// The atan2() function computes the principal value of the arc tangent of y/x,
Expand All @@ -32,4 +40,8 @@ public func atan2(_ y: Float, _ x: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.atan2f(y, x)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atan2f(y, x)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/atanh.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -21,6 +25,10 @@ public func atanh(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.atanhf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atanhf(float)
#endif
}

/// Computes the inverse hyperbolic tangent of arg.
Expand All @@ -38,4 +46,8 @@ public func atanh(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.atanh(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.atanh(double)
#endif
}
12 changes: 12 additions & 0 deletions Sources/FirebladeMath/Functions/ceil.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if FRB_MATH_FOUNDATION
import Foundation
#endif

#if FRB_MATH_DARWIN
import Darwin.C.math
#endif
Expand All @@ -18,6 +22,10 @@ public func ceil(_ float: Float) -> Float {
#if FRB_MATH_GLIBC
return Glibc.ceilf(float)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.ceilf(float)
#endif
}

/// Computes the smallest integer value not less than arg.
Expand All @@ -32,4 +40,8 @@ public func ceil(_ double: Double) -> Double {
#if FRB_MATH_GLIBC
return Glibc.ceil(double)
#endif

#if FRB_MATH_FOUNDATION
return Foundation.ceil(double)
#endif
}
Loading

0 comments on commit 65aa6b5

Please sign in to comment.