A logarithmic number system for Julia.
53 Stars
Updated Last
1 Year Ago
Started In
April 2019


Project Status: Active – The project has reached a stable, usable state and is being actively developed. Stable Documentation Test Status codecov

A logarithmic number system for Julia.

Provides the signed Logarithmic and unsigned ULogarithmic types for representing real numbers on a logarithmic scale.

This is useful when numbers are too big or small to fit accurately into a Float64 and you only really care about magnitude.

For example, it can be useful to represent probabilities in this form, and you don't need to worry about getting zero when multiplying many of them together.


pkg> add LogarithmicNumbers


julia> using LogarithmicNumbers

julia> ULogarithmic(2.7)

julia> float(ans)

julia> x = exp(ULogarithmic, 1000) - exp(ULogarithmic, 998)

julia> float(x) # overflows

julia> log(x)


Exported types

  • ULogarithmic{T} represents a non-negative real number by its logarithm of type T.
  • Logarithmic{T} represents a real number by its absolute value as a ULogarithmic{T} and a sign bit.
  • LogFloat64 is an alias for Logarithmic{Float64}. There are also ULogFloat16, ULogFloat32, ULogFloat64, LogFloat16, and LogFloat32.


  • ULogarithmic(x) and Logarithmic(x) represent the number x.
  • exp(ULogarithmic, logx) represents exp(logx), and logx can be huge. Use this when you already know the logarithm logx of your number x.

Functions in Base

  • Arithmetic: +, -, *, /, ^, inv, prod, sum.
  • Ordering: ==, <, , cmp, isless, isequal, sign, signbit, abs.
  • Logarithm: log, log2, log10, log1p. These are returned as the base (non-logarithmic) type.
  • Conversion: float, unsigned, signed, widen, big. These also operate on types.
  • Special values: zero, one, typemin, typemax.
  • Predicates: iszero, isone, isinf, isfinite, isnan.
  • IO: show, write, read.
  • Random: rand(ULogarithmic) is a random number in the unit interval.
  • Misc: nextfloat, prevfloat, hash.
  • Note: Any functions not mentioned here might be inaccurate.

Interoperability with other packages

It is natural to use this package in conjunction with other packages which return logarithms. The general pattern is that you can use exp(ULogarithmic, logfunc(args...)) instead of func(args...) to get the answer as a logarithmic number. Here are some possibilities for func:

Required Packages

No packages found.