flatten 20260225
This commit is contained in:
74
tjp/core/math/Float16.hpp
Normal file
74
tjp/core/math/Float16.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../types/Types.h"
|
||||
#include "Float16.h"
|
||||
|
||||
namespace tjp::core {
|
||||
|
||||
struct Float16
|
||||
{
|
||||
using V = u16;
|
||||
V v;
|
||||
|
||||
struct Bits { V v; };
|
||||
|
||||
constexpr explicit Float16(Bits bits) :
|
||||
v(bits.v)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Float16() :
|
||||
v(0)
|
||||
{}
|
||||
|
||||
constexpr Float16(const Float16 &rhs) :
|
||||
v(rhs.v)
|
||||
{}
|
||||
|
||||
constexpr Float16(float rhs) :
|
||||
v(convert(rhs))
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Float16(double rhs) :
|
||||
v(convert((float)rhs))
|
||||
{
|
||||
}
|
||||
|
||||
static constexpr V convert(float rhs);
|
||||
static constexpr float convert(V rhs);
|
||||
|
||||
static constexpr Float16 max();
|
||||
static constexpr Float16 min__();
|
||||
static constexpr Float16 negative_max();
|
||||
|
||||
auto ordered() const
|
||||
{
|
||||
u16 sign = v >> 15;
|
||||
if (sign == 0)
|
||||
return v | 0x8000;
|
||||
else
|
||||
return ~v;
|
||||
}
|
||||
|
||||
operator float() const;
|
||||
operator double() const;
|
||||
|
||||
Float16 &operator =(float rhs)
|
||||
{
|
||||
return set(*this, rhs);
|
||||
}
|
||||
|
||||
Float16 &operator =(double rhs)
|
||||
{
|
||||
return set(*this, rhs);
|
||||
}
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
|
||||
#include "Float16.inl"
|
||||
Reference in New Issue
Block a user