Skip to content

Add efficient method for precise integer to floating point conversion #84

@joshbainbridge

Description

@joshbainbridge

Conversion from an integer value across the full range of representable values, to floating point values within the range of [0, 1) is a key part to QMC algorithms, as most calculations are done using integer arithmetic, but the resulting output often needs to be floating point.

The current method employed uses a single division, and relies heavily on the guarantees of IEEE 754. This states that the resulting floating point number in the [0, 1) range will be highly accurate. However, the operation will both round up, and down, and so results in uneven probabilities across the final distribution of values within the representable range.

Rounding up also means a value of 1 itself can be the result. Due to this, we add a max operation to clamp all values to the last representable number before 1, which also adds bias.

A fully accurate mapping can be implemented, but this is computationally much more expensive than a simple division, and often cost more than the creation of the QMC point. Such an implementation was tested in this commit: a97ad21

Add WIP implementation for float mapping using clz

Mapping 32 bit unsigned integers to floating point representation could
be improved as the current method has an undesirable rounding behaviour.

This method using a clz instruction based on the algorithm in Section
2.1 of 'Quasi-Monte Carlo Algorithms (not only) for Graphics Software'
directly maps the unsigned integer bits to the floating point exponent
and mantissa with minimal loss of information.

Testing of this method did show a considerable computational cost when
drawing samples. With some sampler implementations reaching almost 2x
time increase when benchmarked.

Implementing a method with the same output as the above commit, but with at least the same computational cost of the current approach using division would be the best outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions