# Default Real (Float) kind?

**URL:** <https://discourse.julialang.org/t/default-real-float-kind/129631>\
**Category:** Internals & Design\
**Tags:** float\
**Created:** [June 4, 2025, 7:59am UTC](https://discourse.julialang.org/t/default-real-float-kind/129631 "2025-06-04T07:59:20Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 5, 2025, 2:05am UTC](https://discourse.julialang.org/t/default-real-float-kind/129631/16 "2025-06-05T02:05:27Z")

</div>

> [@moble](#):
>
> Definitely thinking about converting to `ChangePrecision`.

As the author of ChangePrecision, I should caution you that it was intended for quick hacks and experiments, not for long-term usage. In the longer term, I tend to recommend writing your code more carefully to think about types and promotion.

Dealing with literals is the easy part of writing type-generic code, in my opinion. Mainly, you use things like rationals instead of decimal constants, and be a little careful with irrationals, e.g. write `2*(π*x)` rather than `2π * x`, and there are a few cases where you need explicit casts.

The tricky part of type-generic code is dealing with **type computations** when the results are of different types than the inputs. For example, I would say that your example above

```julia
function foo(x::T) where T
    let π=T(π)
        x + 2π
    end
end

```

is simply wrong — it will give an error for `foo(3)`, even though `3 + 2π` is perfectly meaningful. You would instead want something like

```julia
foo(x::Number) = x + 2 * oftype(float(x), π)

```

or alternatively if you don’t mind a couple of extra multiplications:

```julia
foo(x::Number) = (x/2 + π)*2

```

Also tricky are cases where you need to allocate types for containers, and need to compute the correct type.

In practice, you usually don’t get type-generic code completely correct the first time, especially if you aren’t used to it, but over time the code becomes more generic as you try it with more types (e.g. complex numbers, dual numbers, …).

---

_[View the full topic](https://discourse.julialang.org/t/default-real-float-kind/129631)._
