Skip to content

Commit aa10f60

Browse files
committed
Introduce FRB_MATH_* defines
1 parent ec67ebd commit aa10f60

31 files changed

+356
-242
lines changed

Package.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ import PackageDescription
66
/// We define global swift settings to control SIMD usage.
77
/// The gist is, that we will import and use SIMD implementations where available.
88
/// Otherwise we fall back to our own implementation.
9-
let swiftSettings: [SwiftSetting]?
9+
var swiftSettings: [SwiftSetting] = []
1010
#if canImport(simd)
11-
swiftSettings = [
12-
.define("FRB_USE_SIMD")
13-
]
14-
#else
15-
swiftSettings = nil
11+
swiftSettings.append(.define("FRB_USE_SIMD"))
1612
#endif
1713

14+
#if canImport(Darwin)
15+
swiftSettings.append(.define("FRB_MATH_DARWIN"))
16+
#endif
17+
18+
#if canImport(Glibc)
19+
swiftSettings.append(.define("FRB_MATH_GLIBC"))
20+
#endif
1821

1922
let package = Package(
2023
name: "FirebladeMath",
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
8+
89
/// Computes the absolute value of a floating point value arg.
910
///
1011
/// - Parameter float: floating point value
@@ -18,9 +19,11 @@ public func abs(_ float: Float) -> Float {
1819
/// - Parameter double: floating point value
1920
/// - Returns: If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes.
2021
public func abs(_ double: Double) -> Double {
21-
#if os(macOS) || os(iOS) || os(tvOS)
22+
#if FRB_MATH_DARWIN
2223
return Darwin.fabs(double)
23-
#elseif os(Linux)
24+
#endif
25+
26+
#if FRB_MATH_GLIBC
2427
return Glibc.fabs(double)
2528
#endif
2629
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
88

99
/// Computes the principal value of the arc cosine of arg.
@@ -13,9 +13,11 @@ import Glibc
1313
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
1414
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
1515
public func acos(_ float: Float) -> Float {
16-
#if os(macOS) || os(iOS) || os(tvOS)
16+
#if FRB_MATH_DARWIN
1717
return Darwin.acosf(float)
18-
#elseif os(Linux)
18+
#endif
19+
20+
#if FRB_MATH_GLIBC
1921
return Glibc.acosf(float)
2022
#endif
2123
}
@@ -27,9 +29,11 @@ public func acos(_ float: Float) -> Float {
2729
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
2830
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
2931
public func acos(_ double: Double) -> Double {
30-
#if os(macOS) || os(iOS) || os(tvOS)
32+
#if FRB_MATH_DARWIN
3133
return Darwin.acos(double)
32-
#elseif os(Linux)
34+
#endif
35+
36+
#if FRB_MATH_GLIBC
3337
return Glibc.acos(double)
3438
#endif
3539
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
8+
89
/// Computes the inverse hyperbolic cosine of arg.
910
///
1011
/// - Parameter double: floating point value representing the area of a hyperbolic sector
1112
/// - Returns: If no errors occur, the inverse hyperbolic cosine of arg (cosh-1
1213
/// (arg), or arcosh(arg)) on the interval [0, +∞], is returned.
1314
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
1415
public func acosh(_ double: Double) -> Double {
15-
#if os(macOS) || os(iOS) || os(tvOS)
16+
#if FRB_MATH_DARWIN
1617
return Darwin.acosh(double)
17-
#elseif os(Linux)
18+
#endif
19+
20+
#if FRB_MATH_GLIBC
1821
return Glibc.acosh(double)
1922
#endif
2023
}
@@ -26,9 +29,11 @@ public func acosh(_ double: Double) -> Double {
2629
/// (arg), or arcosh(arg)) on the interval [0, +∞], is returned.
2730
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
2831
public func acosh(_ float: Float) -> Float {
29-
#if os(macOS) || os(iOS) || os(tvOS)
32+
#if FRB_MATH_DARWIN
3033
return Darwin.acoshf(float)
31-
#elseif os(Linux)
34+
#endif
35+
36+
#if FRB_MATH_GLIBC
3237
return Glibc.acoshf(float)
3338
#endif
3439
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
88

99
/// Computes the principal values of the arc sine of arg.
@@ -13,9 +13,11 @@ import Glibc
1313
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
1414
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
1515
public func asin(_ double: Double) -> Double {
16-
#if os(macOS) || os(iOS) || os(tvOS)
16+
#if FRB_MATH_DARWIN
1717
return Darwin.asin(double)
18-
#elseif os(Linux)
18+
#endif
19+
20+
#if FRB_MATH_GLIBC
1921
return Glibc.asin(double)
2022
#endif
2123
}
@@ -27,9 +29,11 @@ public func asin(_ double: Double) -> Double {
2729
/// If a domain error occurs, an implementation-defined value is returned (NaN where supported).
2830
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
2931
public func asin(_ float: Float) -> Float {
30-
#if os(macOS) || os(iOS) || os(tvOS)
32+
#if FRB_MATH_DARWIN
3133
return Darwin.asinf(float)
32-
#elseif os(Linux)
34+
#endif
35+
36+
#if FRB_MATH_GLIBC
3337
return Glibc.asinf(float)
3438
#endif
3539
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
88

99
/// Computes the inverse hyperbolic sine of arg.
@@ -12,9 +12,12 @@ import Glibc
1212
/// - Returns: If no errors occur, the inverse hyperbolic sine of arg (sinh^-1(arg), or arsinh(arg)), is returned.
1313
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
1414
public func asinh(_ double: Double) -> Double {
15-
#if os(macOS) || os(iOS) || os(tvOS)
15+
#if FRB_MATH_DARWIN
1616
return Darwin.asinh(double)
17-
#elseif os(Linux)
17+
#endif
18+
19+
#if FRB_MATH_GLIBC
20+
1821
return Glibc.asinh(double)
1922
#endif
2023
}
@@ -25,9 +28,12 @@ public func asinh(_ double: Double) -> Double {
2528
/// - Returns: If no errors occur, the inverse hyperbolic sine of arg (sinh^-1(arg), or arsinh(arg)), is returned.
2629
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
2730
public func asinh(_ float: Float) -> Float {
28-
#if os(macOS) || os(iOS) || os(tvOS)
31+
#if FRB_MATH_DARWIN
2932
return Darwin.asinhf(float)
30-
#elseif os(Linux)
33+
#endif
34+
35+
#if FRB_MATH_GLIBC
36+
3137
return Glibc.asinhf(float)
3238
#endif
3339
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
8+
89
/// Computes the principal value of the arc tangent of arg.
910
///
1011
/// - Parameter double: floating point value
1112
/// - Returns: If no errors occur, the arc tangent of arg (arctan(arg)) in the range [-π/2;+π/2] radians, is returned.
1213
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
1314
public func atan(_ double: Double) -> Double {
14-
#if os(macOS) || os(iOS) || os(tvOS)
15+
#if FRB_MATH_DARWIN
1516
return Darwin.atan(double)
16-
#elseif os(Linux)
17+
#endif
18+
19+
#if FRB_MATH_GLIBC
1720
return Glibc.atan(double)
1821
#endif
1922
}
@@ -24,9 +27,11 @@ public func atan(_ double: Double) -> Double {
2427
/// - Returns: If no errors occur, the arc tangent of arg (arctan(arg)) in the range [-π/2;+π/2] radians, is returned.
2528
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
2629
public func atan(_ float: Float) -> Float {
27-
#if os(macOS) || os(iOS) || os(tvOS)
30+
#if FRB_MATH_DARWIN
2831
return Darwin.atanf(float)
29-
#elseif os(Linux)
32+
#endif
33+
34+
#if FRB_MATH_GLIBC
3035
return Glibc.atanf(float)
3136
#endif
3237
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
8+
89
/// The atan2() function computes the principal value of the arc tangent of y/x,
910
/// using the signs of both arguments to determine the quadrant of the return value.
1011
/// - Parameter y: y
1112
/// - Parameter x: x
1213
public func atan2(_ y: Double, _ x: Double) -> Double {
13-
#if os(macOS) || os(iOS) || os(tvOS)
14+
#if FRB_MATH_DARWIN
1415
return Darwin.atan2(y, x)
15-
#elseif os(Linux)
16+
#endif
17+
18+
#if FRB_MATH_GLIBC
1619
return Glibc.atan2(y, x)
1720
#endif
1821
}
@@ -22,9 +25,11 @@ public func atan2(_ y: Double, _ x: Double) -> Double {
2225
/// - Parameter y: y
2326
/// - Parameter x: x
2427
public func atan2(_ y: Float, _ x: Float) -> Float {
25-
#if os(macOS) || os(iOS) || os(tvOS)
28+
#if FRB_MATH_DARWIN
2629
return Darwin.atan2f(y, x)
27-
#elseif os(Linux)
30+
#endif
31+
32+
#if FRB_MATH_GLIBC
2833
return Glibc.atan2f(y, x)
2934
#endif
3035
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
88

99
/// Computes the inverse hyperbolic tangent of arg.
@@ -14,9 +14,11 @@ import Glibc
1414
/// If a pole error occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned (with the correct sign).
1515
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
1616
public func atanh(_ float: Float) -> Float {
17-
#if os(macOS) || os(iOS) || os(tvOS)
17+
#if FRB_MATH_DARWIN
1818
return Darwin.atanhf(float)
19-
#elseif os(Linux)
19+
#endif
20+
21+
#if FRB_MATH_GLIBC
2022
return Glibc.atanhf(float)
2123
#endif
2224
}
@@ -29,9 +31,11 @@ public func atanh(_ float: Float) -> Float {
2931
/// If a pole error occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned (with the correct sign).
3032
/// If a range error occurs due to underflow, the correct result (after rounding) is returned.
3133
public func atanh(_ double: Double) -> Double {
32-
#if os(macOS) || os(iOS) || os(tvOS)
34+
#if FRB_MATH_DARWIN
3335
return Darwin.atanh(double)
34-
#elseif os(Linux)
36+
#endif
37+
38+
#if FRB_MATH_GLIBC
3539
return Glibc.atanh(double)
3640
#endif
3741
}
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
#if canImport(Darwin)
1+
#if FRB_MATH_DARWIN
22
import Darwin.C.math
3-
#elseif canImport(Glibc)
3+
#endif
4+
5+
#if FRB_MATH_GLIBC
46
import Glibc
5-
#else
6-
#error("unsupported platform")
77
#endif
88

99
/// Computes the smallest integer value not less than arg.
1010
///
1111
/// - Parameter float: floating point value
1212
/// - Returns: If no errors occur, the smallest integer value not less than arg, that is ⌈arg⌉, is returned.
1313
public func ceil(_ float: Float) -> Float {
14-
#if os(macOS) || os(iOS) || os(tvOS)
14+
#if FRB_MATH_DARWIN
1515
return Darwin.ceilf(float)
16-
#elseif os(Linux)
16+
#endif
17+
18+
#if FRB_MATH_GLIBC
1719
return Glibc.ceilf(float)
1820
#endif
1921
}
@@ -23,9 +25,11 @@ public func ceil(_ float: Float) -> Float {
2325
/// - Parameter double: floating point value
2426
/// - Returns: If no errors occur, the smallest integer value not less than arg, that is ⌈arg⌉, is returned.
2527
public func ceil(_ double: Double) -> Double {
26-
#if os(macOS) || os(iOS) || os(tvOS)
28+
#if FRB_MATH_DARWIN
2729
return Darwin.ceil(double)
28-
#elseif os(Linux)
30+
#endif
31+
32+
#if FRB_MATH_GLIBC
2933
return Glibc.ceil(double)
3034
#endif
3135
}

0 commit comments

Comments
 (0)