HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
snorm_r8.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../cast.hpp"
8#include <algorithm>
9
10namespace tt {
11
12[[nodiscard]] constexpr int8_t make_snorm_r8_value(float rhs) noexcept
13{
14 return narrow_cast<int8_t>(std::clamp(rhs, -1.0f, 1.0f) * 127.0f);
15}
16
17struct snorm_r8 {
18 int8_t value;
19
20 snorm_r8() = default;
21 snorm_r8(snorm_r8 const &rhs) noexcept = default;
22 snorm_r8(snorm_r8 &&rhs) noexcept = default;
23 snorm_r8 &operator=(snorm_r8 const &rhs) noexcept = default;
24 snorm_r8 &operator=(snorm_r8 &&rhs) noexcept = default;
25 ~snorm_r8() = default;
26
27 explicit snorm_r8(float rhs) noexcept :
28 value(make_snorm_r8_value(rhs)) {}
29
30 snorm_r8 &operator=(float rhs) noexcept {
31 value = make_snorm_r8_value(rhs);
32 return *this;
33 }
34
35 explicit operator float () const noexcept {
36 return narrow_cast<float>(value) / 127.0f;
37 }
38};
39
40}
Definition snorm_r8.hpp:17