Skip to content

Commit 14f97a5

Browse files
committed
Replace magic constants and test all floats
1 parent 27cb1ad commit 14f97a5

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/device/intrinsics/math.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ end
174174
@device_override function Base.exp(h::Float16)
175175
# perform computation in Float32 domain
176176
f = Float32(h)
177-
f = fma(f, reinterpret(Float32, 0x3fb8aa3b), reinterpret(Float32, Base.sign_mask(Float32)))
177+
f = fma(f, reinterpret(Float32, reinterpret(UInt32, log2(Float32(ℯ)))), -0.0f0)
178178
f = @fastmath exp2(f)
179179
r = Float16(f)
180180

@@ -217,7 +217,7 @@ end
217217
@device_override function Base.exp10(h::Float16)
218218
# perform computation in Float32 domain
219219
f = Float32(h)
220-
f = fma(f, reinterpret(Float32, 0x40549A78), reinterpret(Float32, Base.sign_mask(Float32)))
220+
f = fma(f, reinterpret(Float32, reinterpret(UInt32, log2(10.f0))), reinterpret(Float32, Base.sign_mask(Float32)))
221221
f = @fastmath exp2(f)
222222
r = Float16(f)
223223

test/core/device/intrinsics/math.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ using SpecialFunctions
112112
end
113113

114114
@testset "Float16 - $op" for op in (log,exp,exp2,exp10,log2,log10)
115-
@testset "$T" for T in (Float16, )
116-
@test testf(x->op.(x), rand(T, 1))
115+
all_float_16 = collect(reinterpret(Float16, pattern) for pattern in UInt16(0):UInt16(1):typemax(UInt16))
116+
for each_float in all_float_16
117+
@test testf(x->op.(x), Float16[each_float])
117118
end
118119
end
119120

0 commit comments

Comments
 (0)