# Define a more generic meaning for \`typemin\`/\`typemax\`

**URL:** <https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874>\
**Category:** Internals & Design\
**Created:** [August 16, 2023, 6:34pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874 "2023-08-16T18:34:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [August 16, 2023, 6:34pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/1 "2023-08-16T18:34:53Z")

</div>

`typemin(T)` says

> The lowest value representable by the given (real) numeric DataType T.

Suppose we want to be more generic than a “(real) numeric” datatype. What should it say then?

How about

> The minimum value representable by the given `DataType` having a unique minimum value.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [August 16, 2023, 6:40pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/2 "2023-08-16T18:40:53Z")

</div>

one might think from the docstring that

```julia
typemin(::T)

```

returns value `v` such that

```julia
min(v, w) == v

```

for all `w` where `typeof(w) <: T`

however unfortunately this isn’t always true…

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 16, 2023, 6:58pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/3 "2023-08-16T18:58:49Z")

</div>

Could we use `isless`? Is this accurate?

> The lowest value representable by the DataType `T` as ordered by `[`isless`](@ref)`; this value `isless` than all other values of type `T`.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [August 16, 2023, 7:04pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/4 "2023-08-16T19:04:43Z")

</div>

it would have to be `isless || isequal`

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [August 16, 2023, 7:09pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/5 "2023-08-16T19:09:02Z")

</div>

What’s an example of a datatype with multiple equal `typemin` values?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 16, 2023, 7:20pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/6 "2023-08-16T19:20:16Z")

</div>

Conversely, defining `typemax` as

> The highest value representable by the DataType `T` as ordered by `[`isless`](@ref)`; this value `isless` than no other values of type `T`.

seems obvious but breaks in the presence of NaN.

```julia
julia> isless(typemax(Float64), NaN)
true

```

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [August 16, 2023, 7:22pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/7 "2023-08-16T19:22:14Z")

</div>

good point, nvm 😁  
was trying to construct something with subnormals but they don’t work like I thought

but still, it’s not true for `DateTime` as noticed by @Sukera [`typemin`/`typemax` of `DateTime` is not actually the smallest/largest representable `DateTime` · Issue #50931 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/50931)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 16, 2023, 7:35pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/8 "2023-08-16T19:35:41Z")

</div>

I believe the proper predicate is typemax(T) means that !exists x such that `isless(typemax(T), x)`

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [August 16, 2023, 7:38pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/9 "2023-08-16T19:38:29Z")

</div>

```julia
julia> isless(typemax(Float64), NaN)
true

```

Can we say “… in the well ordered subset of values of `T`” or something like that?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 16, 2023, 7:38pm UTC](https://discourse.julialang.org/t/define-a-more-generic-meaning-for-typemin-typemax/102874/10 "2023-08-16T19:38:32Z")

</div>

Yes (I think that’s equivalent to what I wrote above, but it’s late). `x = NaN` exists anyways.
