We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f723667 commit b6c6bc0Copy full SHA for b6c6bc0
base/special/cbrt.jl
@@ -146,3 +146,20 @@ function cbrt(x::Union{Float32,Float64})
146
t = _approx_cbrt(x)
147
return _improve_cbrt(x, t)
148
end
149
+
150
+function cbrt(a::Float16)
151
+ if !isfinite(a) || iszero(a)
152
+ return a
153
+ end
154
+ x = Float32(a)
155
156
+ # 5 bit approximation. Simpler than _approx_cbrt since subnormals can not appear
157
+ u = highword(x) & 0x7fff_ffff
158
+ v = div(u, UInt32(3)) + 0x2a5119f2
159
+ t = copysign(fromhighword(Float32, v), x)
160
161
+ # 2 newton iterations
162
+ t = 0.33333334f0 * (2f0*t + x/(t*t))
163
164
+ return Float16(t)
165
+end
0 commit comments