Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NullNumbers

Build Status Coverage License

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.

Usage

julia> NullNumber() + 10.5
10.5

julia> NullNumber() * Rational(1, 3)
NullNumber()

julia> NullNumber() / 2
NullNumber()

julia> NullNumber()^3
NullNumber()

julia> NullNumber() < 5
true

Features

  • 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

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)
2

Specific behavior

NullNumber 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() * NaN and NullNumber() * Inf both evaluate to NullNumber(), not NaN.
  • NullNumber() / NaN and NullNumber() / 0 both evaluate to NullNumber(), not NaN.
  • x / NullNumber() throws a DivideError
  • NullNumber()^x evaluates to NullNumber() when real(x) > 0, and throws a DomainError otherwise (including real(x) = NaN)
  • x^NullNumber() evaluates one(x) for any x, following the usual x^0 == 1 convention (including Inf^0 == 1 and NaN^0 == 1). The only exception is when x = NullNumber(), for which it throws DomainError

Installation

]add NullNumbers

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages