Skip to content

Commit 198feed

Browse files
committed
pi and e to Float32 and Float16
1 parent 4903c64 commit 198feed

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/device/intrinsics/math.jl

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ using Base.Math: throw_complex_domainerror
88
# - add support for vector types
99
# - consider emitting LLVM intrinsics and lowering those in the back-end
1010

11+
### Constants
12+
@device_override Core.Float32(::typeof(π), ::RoundingMode) = reinterpret(Float32, 0x40490fdb) # 3.1415927f0 reinterpret(UInt32,Float32(reinterpret(Float64,0x400921FB60000000)))
13+
@device_override Core.Float16(::typeof(π), ::RoundingMode) = reinterpret(Float16, 0x4248) # Float16(3.14)
14+
@device_override Core.Float32(::typeof(ℯ), ::RoundingMode) = reinterpret(Float32, 0x402df854) # 2.7182817f0 reinterpret(UInt32,Float32(reinterpret(Float64,0x4005BF0A80000000)))
15+
@device_override Core.Float16(::typeof(ℯ), ::RoundingMode) = reinterpret(Float16, 0x4170) # Float16(2.719)
16+
1117
### Common Intrinsics
1218
@device_function clamp_fast(x::Float32, minval::Float32, maxval::Float32) = ccall("extern air.fast_clamp.f32", llvmcall, Cfloat, (Cfloat, Cfloat, Cfloat), x, minval, maxval)
1319
@device_override Base.clamp(x::Float32, minval::Float32, maxval::Float32) = ccall("extern air.clamp.f32", llvmcall, Cfloat, (Cfloat, Cfloat, Cfloat), x, minval, maxval)

test/device/intrinsics/math.jl

+7
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ end
311311
ir = sprint(io->(@device_code_llvm io=io dump_module=true @metal metal = v"3.0" nextafter_out_test()))
312312
@test occursin(Regex("@air\\.sign\\.f$(8*sizeof(T))"), ir)
313313
end
314+
315+
let # "issue551"
316+
mtl_pi = only(Array(T.(MtlArray([π]), RoundNearest)))
317+
@test mtl_pi == T(π)
318+
mtl_ℯ = only(Array(T.(MtlArray([ℯ]), RoundNearest)))
319+
@test mtl_ℯ == T(ℯ)
320+
end
314321
end
315322
end
316323

0 commit comments

Comments
 (0)