Xcode playground failing on pow() function?

When I run an Xcode playground and use the pow() function, it's ignoring the exponent and returning only the base. If I run this code in a swift playground on an iPad or execute it in the REPL, I get the expected result (9). But in Xcode, it just fails.

Replies

Which version of Xcode ? Which version of iOS ?

I tested in Xcode (15) Playground, no problem:

I tested in code (simulator iOS 15): no problem either, no crash, correct value 9.0

I tested on an iPad with Swift playground: no problem, correct result.

  • It's happening on release Xcode 13 (13A233), on Monterey Beta 9 in a blank playground for MacOS. If I run the same code in an Xcode iOS Playground, or in a Swift Playground on iPadOS (15.0.1), works just fine. When I run a much more complicated formula as part of an iOS app in the Simulator, it's failing there as well. Bizarre.

  • So the culprit seems to be in Monterey…

Add a Comment

So the culprit seems to be in Monterey

Indeed. That’s just weird. And it’s not just pow that triggers the problem. Other functions, like log, behave similarly.

jpurnell, Please file a bug about this, and then post your bug number here, just for the record

Note that Xcode 13.0 is not really rated for macOS 12 beta development — for that you should be using Xcode 13.0b5 which includes the macOS 12 beta SDK — but this problem reproduces with 13.0b5 as well.

ps If you’re doing a bunch of numerics stuff then I recommend that you lean in to the Swift Numerics. The code you posted pulls in the C pow API via Foundation. That API work in Swift, but Swift Numeric is much more thoroughly thought through.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thank you! I just submitted FB9685162. I actually only noticed this because I'm in the process of adopting Swift Numerics and was cross-checking my results. Loving it so far!

  • quick update, still an issue in dev beta 10

  • Persists in 12.0.1 RC (21A558)

Add a Comment

Interesting. I just saw this thread on Swift Forums and I think it explains the behaviour described above.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"