# Should Base.literal\_pow be public?

**URL:** https://discourse.julialang.org/t/should-base-literal-pow-be-public/107942
**Category:** Internals & Design
**Created:** [December 22, 2023, 11:09am UTC](https://discourse.julialang.org/t/should-base-literal-pow-be-public/107942 "2023-12-22T11:09:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [December 22, 2023, 11:09am UTC](https://discourse.julialang.org/t/should-base-literal-pow-be-public/107942/1 "2023-12-22T11:09:38Z")

</div>

Currently, `x^2` is lowered to `Base.literal_pow(^, x, ::Val{2})`. If no method is defined for this, it calls `^(x,2)`. This seems to imply that packages should specialize `Base.literal_pow` for custom types, but they shouldn’t do this if the function is internal to `Base`. This is not a huge issue if one only wants `^(x,p)` and doesn’t care about special values of `p`.

However, if one wishes to specialize `x .^ 2` for a custom `AbstractArray` `x` without implementing a broadcast style, they apparently need to specialize `broadcasted(::typeof(Base.literal_pow), arg1::Base.RefValue{typeof(^)}, x, ::Base.RefValue{Val{2}})`. This requires dispatching on `Base.literal_pow`, which one shouldn’t if `Base.literal_pow` is internal to `Base` (same with `Base.RefValue`, in this case). Moreover, this doesn’t call `Base.broadcasted(::DefaultArrayStyle, ::typeof(^), x, 2)` by default, so there’s no workaround available, unlike the non-broadcast version. (Arguably, such a method may be added.)

The function [is used](https://juliahub.com/ui/Search?q=literal_pow&type=code) by a reasonably large number of packages already, so it might make some sense to declare this to be public.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [December 25, 2023, 12:40am UTC](https://discourse.julialang.org/t/should-base-literal-pow-be-public/107942/2 "2023-12-25T00:40:28Z")

</div>

I hope the function gets a better name than `literal_pow` before it becomes public.
