C 头文件中的 Swift 数学函数

标签 swift

我使用的是 swift 5.0

让 a = Darwin.lgamma(0.2)

内部Math.h

extern float lgammaf(float);
extern double lgamma(double);
extern long double lgammal(long double);

编译总是警告 lgamma 的不明确调用

最佳答案

这对我有用

  internal func lgamma1<T: FloatingPoint>(_ x: T) -> T {
      switch x {
      case let d as Double:
        return lgamma(d) as Double as! T
      case let f as Float:
        return lgammaf(f) as! T
      #if arch(x86_64)
      case let lf as Float80:
        return lgammal(lf) as! T
      #endif
      default:
        return T.nan
      }
    }

关于C 头文件中的 Swift 数学函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58662428/

相关文章:

arrays - 从另一个对象数组创建一个对象数组,稍后使用 map 重建原始对象数组

ios - 使用 Swift 将 UIView 的坐标移动到 LLO

swift - 显示帮助文本以了解 Swift 中函数的功能

ios - 核心数据更改处理时出错

ios - 在 VIewController 之间共享数据 - iOS

swift - 编译 CoreLibs Foundation 时出错

ios - 在 map View 上获取注释框

ios - 重写 UITextField 委托(delegate)方法

swift - RxSwift 中多节表格 View 的 ViewModel 输入和输出

ios - SwiftUI List 数据源为空时,如何在 View 中心显示文本消息?