# Understanding how to implement numbers in Julia

**URL:** <https://discourse.julialang.org/t/understanding-how-to-implement-numbers-in-julia/51643>\
**Category:** General Usage\
**Created:** [December 11, 2020, 12:57am UTC](https://discourse.julialang.org/t/understanding-how-to-implement-numbers-in-julia/51643 "2020-12-11T00:57:17Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [December 11, 2020, 8:13am UTC](https://discourse.julialang.org/t/understanding-how-to-implement-numbers-in-julia/51643/3 "2020-12-11T08:13:18Z")

</div>

I don’t think the interface for numbers is formally and extensively documented (yet?), but there are a couple of threads here on discourse where this topic was discussed. You might find valuable information there:

> [@Interface for \`Number\`](https://discourse.julialang.org/t/interface-for-number/2723):
>
> I recently ran into an issue overriding zero for my own Number: julia\> immutable Infinity \<: Number end julia\> Base.zero(::Infinity) = 0 julia\> import Base: + julia\> +(::Infinity,::Int) = Infinity() + (generic function with 181 methods) julia\> reduce(+,[Infinity(),Infinity()]) ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Infinity This may have arisen from a call to the constructor Infinity(...), since type constructors fall back to convert methods. Stack…

> [@Codify best practices for custom types](https://discourse.julialang.org/t/codify-best-practices-for-custom-types/42176):
>
> The announcement for [CSV.jl v0.7](https://discourse.julialang.org/t/ann-csv-jl-0-7-release/42162) includes this new capability: Custom types can now be passed in the … types keyword …, fast parsing is supported for all Integer and AbstractFloat types; other custom types need to support zero(T) and parse(T, str) to be parsed correctly. That a custom numeric type T support zero(T) is entirely reasonable and of great utility to clients and other users of that type. With T a natural (whole) number type, zero(T) would throw a DomainError; and imo that…

From what I see and off the top of my head, I’d say that apart from promotion rules, you’ll still be missing:

- a unary minus operator
- comparison operators
- probably a `zero` method

---

_[View the full topic](https://discourse.julialang.org/t/understanding-how-to-implement-numbers-in-julia/51643)._
