F16 fixes

This commit is contained in:
Jorijn van der Graaf 2026-03-24 03:48:56 +01:00
commit 6e6530290b
3 changed files with 189 additions and 506 deletions

View file

@ -458,34 +458,24 @@ namespace Crafter {
}
template <typename T, std::uint32_t Aligment>
struct std::formatter<Crafter::Vector<T, 2, Aligment>> : std::formatter<std::string> {
auto format(const Crafter::Vector<T, 2, Aligment>& obj, format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{{{}, {}}}",
obj.x, obj.y
), ctx);
template <typename T, std::uint32_t Len, std::uint32_t Aligment>
struct std::formatter<Crafter::Vector<T, Len, Aligment>> : std::formatter<std::string> {
auto format(const Crafter::Vector<T, Len, Aligment>& vec, format_context& ctx) const {
std::string out = "{";
for(std::uint32_t i2 = 0; i2 < Len; i2++) {
if constexpr(std::same_as<T, _Float16>) {
out += std::format("{}", static_cast<float>(vec.v[i2]));
} else {
out += std::format("{}", vec.v[i2]);
}
if (i2 + 1 < Len) out += ",";
}
out += "}";
return std::formatter<std::string>::format(out, ctx);
}
};
template <typename T, std::uint32_t Aligment>
struct std::formatter<Crafter::Vector<T, 3, Aligment>> : std::formatter<std::string> {
auto format(const Crafter::Vector<T, 3, Aligment>& obj, format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{{{}, {}, {}}}",
obj.x, obj.y, obj.z
), ctx);
}
};
template <typename T, std::uint32_t Aligment>
struct std::formatter<Crafter::Vector<T, 4, Aligment>> : std::formatter<std::string> {
auto format(const Crafter::Vector<T, 4, Aligment>& obj, format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{{{}, {}, {}, {}}}",
(float)obj.x, (float)obj.y, (float)obj.z, (float)obj.w
), ctx);
}
};
template <typename T, std::uint32_t Len, std::uint32_t Aligment, typename BT>
constexpr Crafter::Vector<T, Len, Aligment> operator*(BT b, const Crafter::Vector<T, Len, Aligment>& v) requires std::is_arithmetic_v<BT> {
return v * b;