This commit is contained in:
Ray
2025-01-28 16:19:39 +01:00
3 changed files with 21 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.25)
#this change avoid the warning that appear when we include raylib using Cmake fatch content
project(raylib) project(raylib)
# Avoid excessive expansion of variables in conditionals. In particular, if # Avoid excessive expansion of variables in conditionals. In particular, if

View File

@@ -742,7 +742,7 @@ rcore.o : rcore.c raylib.h rlgl.h utils.h raymath.h rcamera.h rgestures.h
# Compile rglfw module # Compile rglfw module
rglfw.o : rglfw.c rglfw.o : rglfw.c
$(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) $(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) -U_GNU_SOURCE
# Compile shapes module # Compile shapes module
rshapes.o : rshapes.c raylib.h rlgl.h rshapes.o : rshapes.c raylib.h rlgl.h

View File

@@ -5390,13 +5390,19 @@ static float HalfToFloat(unsigned short x)
{ {
float result = 0.0f; float result = 0.0f;
union
{
float fm;
unsigned int ui;
} uni;
const unsigned int e = (x & 0x7C00) >> 10; // Exponent const unsigned int e = (x & 0x7C00) >> 10; // Exponent
const unsigned int m = (x & 0x03FF) << 13; // Mantissa const unsigned int m = (x & 0x03FF) << 13; // Mantissa
const float fm = (float)m; uni.fm = (float)m;
const unsigned int v = (*(unsigned int *)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format const unsigned int v = uni.ui >> 23; // Evil log2 bit hack to count leading zeros in denormalized format
const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized uni.ui = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized
result = *(float *)&r; result = uni.fm;
return result; return result;
} }
@@ -5406,7 +5412,14 @@ static unsigned short FloatToHalf(float x)
{ {
unsigned short result = 0; unsigned short result = 0;
const unsigned int b = (*(unsigned int *) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa union
{
float fm;
unsigned int ui;
} uni;
uni.fm = x;
const unsigned int b = uni.ui + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
const unsigned int e = (b & 0x7F800000) >> 23; // Exponent const unsigned int e = (b & 0x7F800000) >> 23; // Exponent
const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding