Skip to content

Override ^(Float, Int64) to avoid Float64 widening#428

Merged
maleadt merged 1 commit intomasterfrom
tb/powi
Apr 15, 2026
Merged

Override ^(Float, Int64) to avoid Float64 widening#428
maleadt merged 1 commit intomasterfrom
tb/powi

Conversation

@maleadt
Copy link
Copy Markdown
Member

@maleadt maleadt commented Apr 15, 2026

Base.^(::Union{Float16,Float32,Float64}, ::Int64) widens Float32/16 through Float64 (via power_by_squaring), which breaks on backends without FP64 support like oneAPI on some devices, and leaves a runtime pown call in the generated code in all cases.

Needed for JuliaGPU/GPUArrays.jl#707

Base.`^(::Union{Float16,Float32,Float64}, ::Int64)` widens Float32/16 through
Float64 (via `power_by_squaring`), which breaks on backends without FP64
support like oneAPI on some devices, and leaves a runtime `pown` call in the
generated code in all cases.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.26%. Comparing base (3c46b32) to head (a5dac76).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #428   +/-   ##
=======================================
  Coverage   80.26%   80.26%           
=======================================
  Files          12       12           
  Lines         745      745           
=======================================
  Hits          598      598           
  Misses        147      147           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt maleadt merged commit fa8d2cb into master Apr 15, 2026
37 of 38 checks passed
@maleadt maleadt deleted the tb/powi branch April 15, 2026 08:10
y == 1 && return x
y == 2 && return x * x
y == 3 && return x * x * x
x ^ (y % Int32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this normally overflow to Inf instead of wrapping? Maybe replace y%Int32 with Float32(y)?

julia> 2.0^(Int64(2)^32 % Int32)
1.0

julia> 2.0^(Int64(2)^32)
Inf

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah OK that's sloppy. Thanks; I'll create a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants