NullNumbers is a lightweight Julia package providing a numeric type that can explicitly represent a “null” value while still participating in arithmetic. Null values act as a zero-like element: they are neutral for addition but absorb any numeric operand in multiplication.
julia> NullNumber() + 10.5
10.5
julia> NullNumber() * Rational(1, 3)
NullNumber()
julia> NullNumber() / 2
NullNumber()
julia> NullNumber()^3
NullNumber()
julia> NullNumber() < 5
true
- A custom numeric type representing a null number
- Basic arithmetic operations and functions
- Useful to generate an instance of a function with hardcoded null parameters
- Seamless integration with Julia's type system
imagz(x) is similar to imag(x), except that it returns NullNumber()
for any non-Complex input.
julia> imagz(3.0)
NullNumber()
julia> imagz(1 + 2im)
2NullNumber is a hardcoded zero, not the IEEE zero of 0.0. It is meant for
cases where a parameter is known at compile time to be absent, so that the
compiler can eliminate the operations touching it. As a result, it does not
follow IEEE float semantics in a few places:
NullNumber() * NaNandNullNumber() * Infboth evaluate toNullNumber(), notNaN.NullNumber() / NaNandNullNumber() / 0both evaluate toNullNumber(), notNaN.x / NullNumber()throws aDivideErrorNullNumber()^xevaluates toNullNumber()whenreal(x) > 0, and throws aDomainErrorotherwise (includingreal(x) = NaN)x^NullNumber()evaluatesone(x)for anyx, following the usualx^0 == 1convention (includingInf^0 == 1andNaN^0 == 1). The only exception is whenx = NullNumber(), for which it throwsDomainError
]add NullNumbers