18 explicit constexpr NormalizedF32(
float value) : value_(value) {}
23 [[nodiscard]]
static std::optional<NormalizedF32>
create(
float value) {
return newFloat(value); }
25 [[nodiscard]]
static std::optional<NormalizedF32> newFloat(
float value);
28 [[nodiscard]]
static NormalizedF32 fromU8(std::uint8_t value);
30 [[nodiscard]]
constexpr float get()
const {
return value_; }
32 constexpr bool operator==(
const NormalizedF32&)
const =
default;
33 constexpr bool operator<(
const NormalizedF32& o)
const {
return value_ < o.value_; }
34 constexpr bool operator<=(
const NormalizedF32& o)
const {
return value_ <= o.value_; }
35 constexpr bool operator>(
const NormalizedF32& o)
const {
return value_ > o.value_; }
36 constexpr bool operator>=(
const NormalizedF32& o)
const {
return value_ >= o.value_; }
38 [[nodiscard]]
static constexpr NormalizedF32 zero() {
return NormalizedF32(0.0f); }
39 [[nodiscard]]
static constexpr NormalizedF32 one() {
return NormalizedF32(1.0f); }
45inline constexpr NormalizedF32 NormalizedF32::ZERO = NormalizedF32(0.0f);
46inline constexpr NormalizedF32 NormalizedF32::ONE = NormalizedF32(1.0f);
50class NormalizedF32Exclusive {
52 static const NormalizedF32Exclusive ANY;
53 static const NormalizedF32Exclusive HALF;
55 [[nodiscard]]
static std::optional<NormalizedF32Exclusive> create(
float v);
56 [[nodiscard]]
static NormalizedF32Exclusive newBounded(
float v);
58 [[nodiscard]]
constexpr float get()
const {
return value_; }
59 [[nodiscard]] NormalizedF32 toNormalized()
const;
61 constexpr bool operator==(
const NormalizedF32Exclusive&)
const =
default;
62 constexpr bool operator<(
const NormalizedF32Exclusive& o)
const {
return value_ < o.value_; }
65 explicit constexpr NormalizedF32Exclusive(
float v) : value_(v) {}
69inline constexpr NormalizedF32Exclusive NormalizedF32Exclusive::ANY = NormalizedF32Exclusive(0.5f);
70inline constexpr NormalizedF32Exclusive NormalizedF32Exclusive::HALF = NormalizedF32Exclusive(0.5f);
74class NonZeroPositiveF32 {
76 [[nodiscard]]
static std::optional<NonZeroPositiveF32> create(
float v);
77 [[nodiscard]]
constexpr float get()
const {
return value_; }
80 explicit constexpr NonZeroPositiveF32(
float v) : value_(v) {}
88 [[nodiscard]]
static std::optional<FiniteF32> create(
float v);
89 [[nodiscard]]
constexpr float get()
const {
return value_; }
92 explicit constexpr FiniteF32(
float v) : value_(v) {}
97[[nodiscard]] std::int32_t saturateCastI32(
float x);
99[[nodiscard]] std::int32_t saturateCastI32(
double x);
101[[nodiscard]] std::int32_t saturateFloorToI32(
float x);
103[[nodiscard]] std::int32_t saturateCeilToI32(
float x);
105[[nodiscard]] std::int32_t saturateRoundToI32(
float x);
107[[nodiscard]] std::int32_t f32As2sCompliment(
float x);
A float guaranteed to be in [0, 1].
Definition FloatingPoint.h:12
static NormalizedF32 newClamped(float value)
Clamps to [0,1].
static std::optional< NormalizedF32 > create(float value)
Returns nullopt if outside [0,1] or non-finite.
Definition FloatingPoint.h:23