Non-negative integers

There isn’t such a type for floating-point numbers; you could define one, of course, but this is something that’s probably better done with a runtime argument check:

function f(x::Real)
     x ≥ 0 || throw(DomainError("negative x=$x not allowed"))
    ...
end

Note that if x is an Unsigned type (like UInt, and also things like Rational{UInt}), the compiler will know that x ≥ 0 is always true and optimize out the check.

1 Like