Brain floating point representation class */
| 106 | |
| 107 | /** Brain floating point representation class */ |
| 108 | class bfloat16 final |
| 109 | { |
| 110 | public: |
| 111 | /** Default Constructor */ |
| 112 | bfloat16() : value(0) |
| 113 | { |
| 114 | } |
| 115 | /** Constructor |
| 116 | * |
| 117 | * @param[in] v Floating-point value |
| 118 | */ |
| 119 | explicit bfloat16(float v) : value(float_to_bf16(v)) |
| 120 | { |
| 121 | } |
| 122 | /** Constructor |
| 123 | * |
| 124 | * @param[in] v Floating-point value |
| 125 | * @param[in] portable bool to indicate the conversion is to be done in a backward compatible way |
| 126 | */ |
| 127 | bfloat16(float v, bool portable) : value(0) |
| 128 | { |
| 129 | value = portable ? portable_float_to_bf16(v) : float_to_bf16(v); |
| 130 | } |
| 131 | /** Assignment operator |
| 132 | * |
| 133 | * @param[in] v Floating point value to assign |
| 134 | * |
| 135 | * @return The updated object |
| 136 | */ |
| 137 | bfloat16 &operator=(float v) |
| 138 | { |
| 139 | value = float_to_bf16(v); |
| 140 | return *this; |
| 141 | } |
| 142 | /** Floating point conversion operator |
| 143 | * |
| 144 | * @return Floating point representation of the value |
| 145 | */ |
| 146 | operator float() const |
| 147 | { |
| 148 | return bf16_to_float(value); |
| 149 | } |
| 150 | /** Lowest representative value |
| 151 | * |
| 152 | * @return Returns the lowest finite value representable by bfloat16 |
| 153 | */ |
| 154 | static bfloat16 lowest() |
| 155 | { |
| 156 | bfloat16 val; |
| 157 | val.value = 0xFF7F; |
| 158 | return val; |
| 159 | } |
| 160 | /** Largest representative value |
| 161 | * |
| 162 | * @return Returns the largest finite value representable by bfloat16 |
| 163 | */ |
| 164 | static bfloat16 max() |
| 165 | { |
no test coverage detected