Skip to content

Commit 682d498

Browse files
authored
Yams: add an alias to explicitly dispatch pow (jpsim#281)
We must disambiguate `Double.pow(_: Double, _: Double) -> Double` and `__C.pow(_: Double, _: Double) -> Double` as the Swift for TensorFlow branch adds the former into the standard library. The explicit module dispatch ensures that we make the overload resolution unambiguous allowing building Yams.
1 parent ae37c14 commit 682d498

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Sources/Yams/Representer.swift

+16-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ import Foundation
1414
import ucrt
1515
#endif
1616

17+
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
18+
import Darwin
19+
fileprivate let cpow: (_: Double, _: Double) -> Double = Darwin.pow
20+
#elseif os(Windows)
21+
import ucrt
22+
fileprivate let cpow: (_: Double, _: Double) -> Double = ucrt.pow
23+
#else
24+
import Glibc
25+
fileprivate let cpow: (_: Double, _: Double) -> Double = Glibc.pow
26+
#endif
27+
1728
public extension Node {
1829
/// Initialize a `Node` with a value of `NodeRepresentable`.
1930
///
@@ -130,13 +141,11 @@ private extension TimeInterval {
130141
func separateFractionalSecond(withPrecision precision: Int) -> (integral: TimeInterval, fractional: Int) {
131142
var integral = 0.0
132143
let fractional = modf(self, &integral)
133-
// Can't use `pow` free function due to https://bugs.swift.org/browse/TF-1203.
134-
// TODO: Remove condition after that bug is fixed.
135-
#if canImport(TensorFlow)
136-
let radix = Double.pow(10.0, Double(precision))
137-
#else
138-
let radix = pow(10.0, Double(precision))
139-
#endif
144+
145+
// TODO(TF-1203): Can't use `pow` free function due to
146+
// https://bugs.swift.org/browse/TF-1203.
147+
let radix = cpow(10.0, Double(precision))
148+
140149
let rounded = Int((fractional * radix).rounded())
141150
let quotient = rounded / Int(radix)
142151
return quotient != 0 ? // carry-up?

0 commit comments

Comments
 (0)