Is sin missing for Float16?

I try to compile the following snippet with the latest development snapshot from today;

import Foundation

let a: Float16 = 1.0
let b = sin(a)

which gives the following error:

bla.swift:4:9: error: no exact matches in call to global function 'sin'
let b = sin(a)
^
Foundation.sin:1:13: note: candidate expects value of type 'CGFloat' for parameter #1
public func sin(_ x: CGFloat) -> CGFloat
^
Glibc.sin:1:13: note: candidate expects value of type 'Float' for parameter #1
public func sin(_ x: Float) -> Float
^
Glibc.sin:1:13: note: candidate expects value of type 'Float80' for parameter #1
public func sin(_ x: Float80) -> Float80
^
SwiftGlibc.sin:1:13: note: candidate expects value of type 'Double' for parameter #1
public func sin(_ __x: Double) -> Double

Is this a bug?

sin functions come from Glibc, not from swift standard library (you can check that by commenting out import Foundation, then all sin will stop working). I don't think there is a Float16 equivalent in C so it's not surprising that Glibc doesn't have a sin for it.

It's not a bug, it's a lack of a feature. This proposal should help when it will be implemented swift-evolution/0246-mathable.md at master · apple/swift-evolution · GitHub

sin, plus the rest of SE-0246, as well as a bunch of other stuff, is available for Float16 in the numerics package on the swift-5.3 branch (and will be merged to master once -5.3 is released).

import RealModule

let a = Float16.sin(1)
1 Like