Skip to content

Commit

Permalink
Added functions for converting normalized integer of various sizes to…
Browse files Browse the repository at this point in the history
… float.
  • Loading branch information
fLindahl committed Nov 22, 2024
1 parent 48601b3 commit 8a9bb38
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions code/foundation/math/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,47 @@ pointerhash(void* ptr)
return (uint32_t) (((uintptr_t)(void *)ptr) % 4294967291u);
}


//------------------------------------------------------------------------------
/**
convert normalized uint16_t to float
*/
inline float
normtofloat(uint16_t value)
{
return (float)value / 65535.0f;
}

//------------------------------------------------------------------------------
/**
convert normalized int16_t to float
*/
inline float
normtofloat(int16_t value)
{
return Math::max((float)value / 32767.0f, -1.0f);
}

//------------------------------------------------------------------------------
/**
convert normalized uint8_t to float
*/
inline float
normtofloat(uint8_t value)
{
return (float)value / 255.0f;
}

//------------------------------------------------------------------------------
/**
convert normalized int8_t to float
*/
inline float
normtofloat(int8_t value)
{
return Math::max((float)value / 127.0f, -1.0f);
}

} // namespace Math

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -849,4 +890,5 @@ operator"" _deg(unsigned long long deg)
{
return Math::rad2deg(deg);
}

//------------------------------------------------------------------------------

0 comments on commit 8a9bb38

Please sign in to comment.