# Detect if constant

**URL:** <https://discourse.julialang.org/t/detect-if-constant/100246>\
**Category:** General Usage\
**Tags:** constant-propagation\
**Created:** [June 12, 2023, 7:56pm UTC](https://discourse.julialang.org/t/detect-if-constant/100246 "2023-06-12T19:56:52Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 15, 2023, 10:55am UTC](https://discourse.julialang.org/t/detect-if-constant/100246/8 "2023-06-15T10:55:27Z")

</div>

I’ve also asked about this before, and I still think that it would be a really useful thing to have.

> [@Branch on whether a value is known to the compiler](https://discourse.julialang.org/t/branch-on-whether-a-value-is-known-to-the-compiler/34850):
>
> Here’s something that I’ve been thinking about: What if there was a way to write code that works differently depending on whether some value is known to the compiler? As an example, let’s say I could write: @inline function ^(x, p::Integer) if @known p literal\_pow(^, x, Val(p)) else power\_by\_squaring(x, p) end end where @known would be a special macro that would tell the compiler to first do some amount of inlining and constant-folding, then check whether the value o…

---

_[View the full topic](https://discourse.julialang.org/t/detect-if-constant/100246)._
