From d0dbef20c798873f7a1a47dea60bf9d0b23ca327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 10 Mar 2025 11:03:17 +0100 Subject: [PATCH] Fix handling of inf and nan in TFloat16 --- tfloat16.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tfloat16.h b/tfloat16.h index 3e5237e..70ea8eb 100644 --- a/tfloat16.h +++ b/tfloat16.h @@ -27,6 +27,12 @@ public: b16 |= sign; b16 |= mantisa; } + else if(exp == 255)//inf or nan + { + b16 = 0x7c00; + b16 |= sign; + b16 |= mantisa; + } else if(exp > 142) { b16 = 0x7c00;// inf @@ -51,7 +57,8 @@ public: if(b16) { i |= sign << 16; - i |= (exp + 112) << 23; + if(exp==31)i |= 0x7f800000; + else i |= (exp + 112) << 23; i |= (b16 & 0x3ff) << 13; } return *reinterpret_cast(&i);