# Printing typemax as Inf

**URL:** <https://discourse.julialang.org/t/printing-typemax-as-inf/12509>\
**Category:** General Usage\
**Created:** [July 19, 2018, 7:07pm UTC](https://discourse.julialang.org/t/printing-typemax-as-inf/12509 "2018-07-19T19:07:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [July 19, 2018, 7:07pm UTC](https://discourse.julialang.org/t/printing-typemax-as-inf/12509/1 "2018-07-19T19:07:02Z")

</div>

I’d like add something to a Base method. In particular, I’d like to override Base.print for a particular type but still need to call the original function in most cases. The problem is that the original function is lost once I override it.  
Any thoughts on how to do this?

To be more specific, I’d like to make Base.print show Inf and -Inf when the argument is typemax or typemin.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 19, 2018, 7:15pm UTC](https://discourse.julialang.org/t/printing-typemax-as-inf/12509/2 "2018-07-19T19:15:58Z")

</div>

You could use `invoke` but they’re are other (arguably better) ways of solving the problem.

---

<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:** [July 19, 2018, 7:37pm UTC](https://discourse.julialang.org/t/printing-typemax-as-inf/12509/3 "2018-07-19T19:37:53Z")

</div>

You can create a `print` method in your own module or in the `Main` module.  
Start by defining

```julia
print(args...) = Base.print(args...)

```

Now you can define your own methods like

```julia
print(x::Int) = Base.print(x == typemax(Int) ? "Inf" : x)

```

Now import this `print` into every module where you want to change the behavior the function.  
(You can use `eval` to inject code into a module without having to modify that modules’ source code.)  
When you want to use the original function, you simply call `Base.print`.

Edit: I haven’t actually tried this. Now that I think about it, there will probably be world age issues.
