OpenQMC API
Loading...
Searching...
No Matches
float.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
7
8#pragma once
9
10#include "gpu.h"
11
12#include <cmath>
13#include <cstdint>
14
31
32namespace oqmc
33{
34
35constexpr auto floatOneOverUintMax = 2.3283064365386962890625e-10f;
36constexpr auto floatOneMinusEpsilon = 0.999999940395355224609375f;
37
47OQMC_HOST_DEVICE inline float uintToFloat(std::uint32_t value)
48{
49 // This method is inspired by the method used by Matt Pharr in PBRT v4. It
50 // has the undesirable property of floating point values rounding up to the
51 // nearest representable number to reduce error. This gives the potential
52 // for an output equal to one, requiring a min operation. However, this was
53 // considered the best tradeoff when compared to other methods.
54
55 // Marc Reynolds gives an option where 8 bits of precision is first removed
56 // (http://marc-b-reynolds.github.io/distribution/2017/01/17/DenseFloat.html)
57 // prior to division. This removes the need for any min operations, but also
58 // looses us a good amount of precision sub one half.
59
60 // An alternative algorithm using a clz operation is detailed in Section 2.1
61 // of 'Quasi-Monte Carlo Algorithms (not only) for Graphics Software'. This
62 // optimally maps the unsinged integer bits to the floating point exponent
63 // and mantissa. However, after benchmarking this alternative method the
64 // cost when drawing samples was a 2x time increase for some samplers.
65
67}
68
69} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
float uintToFloat(std::uint32_t value)
Convert an integer into a [0, 1) float.
Definition float.h:47
Definition bntables.h:21
constexpr auto floatOneMinusEpsilon
max flt
Definition float.h:36
constexpr auto floatOneOverUintMax
0x1p-32
Definition float.h:35