swift-numerics
swift-numerics copied to clipboard
BFloat16
Hi there! I’ve implemented bfloat in swift over here.
If you want to I am open to having it be part of numerics. If so lmk what changes would be needed to include it :)
Any feedback you have is very welcome ☺️
Tagging you @stephentyrone since you're active in the repo, it's been a little while, and I don't know if anyone has seen this :)
I've had a look out of curiosity (I'm not a project member here), and I've found a few points:
ExpressibleByIntegerLiteralshould not be used to supply bit masks. It should produce the sameBFloat16value for e.g.8as for8.0.- Having functions named
fromFloat(_)andtoFloat()isn't idiomatic Swift code. It's probably better to change the latter to a getter namedfloat. - On that note, it's surprising to me that
fromFloat(_)andinit(_ value: Float)do different things. I would expect only the initializer to exist.
And some tiny suggestions:
BFloat16could have a no-argument constructor that produces a zero value.- Add conformance to the
Sendableprotocol. - There could be an extension to the
Floattype that adds a constructor taking aBFloat16parameter.
Thank you so much for the detailed feedback! As you probably saw in the repo description this is my first time writing any swift so I really need any feedback and critique you have to offer ;)
I'll go through your points, make a PR, and add you for a review if you're up for it? ☺️ (May take a while until I have time to do it)