6#ifndef MATERIALX_RENDER_TYPES_H
7#define MATERIALX_RENDER_TYPES_H
63 explicit Half(
float value) : _data(toFloat16(value)) { }
64 operator float()
const {
return toFloat32(_data); }
66 bool operator==(
Half rhs)
const {
return float(*
this) == float(rhs); }
67 bool operator!=(
Half rhs)
const {
return float(*
this) != float(rhs); }
68 bool operator<(
Half rhs)
const {
return float(*
this) < float(rhs); }
69 bool operator>(
Half rhs)
const {
return float(*
this) > float(rhs); }
70 bool operator<=(
Half rhs)
const {
return float(*
this) <= float(rhs); }
71 bool operator>=(
Half rhs)
const {
return float(*
this) >= float(rhs); }
73 Half operator+(
Half rhs)
const {
return Half(
float(*
this) +
float(rhs)); }
74 Half operator-(
Half rhs)
const {
return Half(
float(*
this) -
float(rhs)); }
75 Half operator*(
Half rhs)
const {
return Half(
float(*
this) *
float(rhs)); }
76 Half operator/(
Half rhs)
const {
return Half(
float(*
this) /
float(rhs)); }
78 Half& operator+=(
Half rhs) {
return operator=(*
this + rhs); }
79 Half& operator-=(
Half rhs) {
return operator=(*
this - rhs); }
80 Half& operator*=(
Half rhs) {
return operator=(*
this * rhs); }
81 Half& operator/=(
Half rhs) {
return operator=(*
this / rhs); }
83 Half operator-()
const {
return Half(-
float(*
this)); }
93 static constexpr int const shift = 13;
94 static constexpr int const shiftSign = 16;
96 static constexpr int32_t
const infN = 0x7F800000;
97 static constexpr int32_t
const maxN = 0x477FE000;
98 static constexpr int32_t
const minN = 0x38800000;
99 static constexpr int32_t
const signN = (int32_t) 0x80000000;
101 static constexpr int32_t
const infC = infN >> shift;
102 static constexpr int32_t
const nanN = (infC + 1) << shift;
103 static constexpr int32_t
const maxC = maxN >> shift;
104 static constexpr int32_t
const minC = minN >> shift;
105 static constexpr int32_t
const signC = (int32_t) 0x00008000;
107 static constexpr int32_t
const mulN = 0x52000000;
108 static constexpr int32_t
const mulC = 0x33800000;
110 static constexpr int32_t
const subC = 0x003FF;
111 static constexpr int32_t
const norC = 0x00400;
113 static constexpr int32_t
const maxD = infC - maxC - 1;
114 static constexpr int32_t
const minD = minC - subC - 1;
116 static uint16_t toFloat16(
float value)
120 uint32_t sign = (uint32_t) (v.si & signN);
124 s.si = (int32_t) (s.f * v.f);
125 v.si ^= (s.si ^ v.si) & -(minN > v.si);
126 v.si ^= (infN ^ v.si) & -((infN > v.si) & (v.si > maxN));
127 v.si ^= (nanN ^ v.si) & -((nanN > v.si) & (v.si > infN));
129 v.si ^= ((v.si - maxD) ^ v.si) & -(v.si > maxC);
130 v.si ^= ((v.si - minD) ^ v.si) & -(v.si > subC);
131 return (uint16_t) (v.ui | sign);
134 static float toFloat32(uint16_t value)
138 int32_t sign = v.si & signC;
141 v.si ^= ((v.si + minD) ^ v.si) & -(v.si > subC);
142 v.si ^= ((v.si + maxD) ^ v.si) & -(v.si > maxC);
146 int32_t mask = (norC > v.si) ? -1 : 1;
148 v.si ^= (s.si ^ v.si) & mask;
Macros for declaring imported and exported symbols.
A three-component color value (double-precision)
Definition: Types.h:47
A lightweight 16-bit half-precision float class.
Definition: Types.h:61
A tag class for constructing vectors and matrices without initialization.
Definition: Types.h:46
A vector of three floating-point values (double-precision)
Definition: Types.h:21
A vector of four floating-point values (double-precision)
Definition: Types.h:34
The class template for vectors of scalar values.
Definition: Types.h:54