2010-05-27 23:19:24 +00:00
|
|
|
#pragma once
|
2008-07-31 09:55:22 +00:00
|
|
|
#ifndef NV_MATH_HALF_H
|
|
|
|
#define NV_MATH_HALF_H
|
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
#include "nvmath.h"
|
2008-07-31 09:55:22 +00:00
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
namespace nv {
|
2008-07-31 09:55:22 +00:00
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
uint32 half_to_float( uint16 h );
|
|
|
|
uint16 half_from_float( uint32 f );
|
|
|
|
|
|
|
|
// Does not handle NaN or infinity.
|
|
|
|
uint32 fast_half_to_float( uint16 h );
|
|
|
|
|
2011-04-06 02:41:15 +00:00
|
|
|
inline uint16 to_half(float c) {
|
|
|
|
union { float f; uint32 u; } f;
|
|
|
|
f.f = c;
|
|
|
|
return nv::half_from_float( f.u );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float to_float(uint16 c) {
|
|
|
|
union { float f; uint32 u; } f;
|
|
|
|
f.u = nv::fast_half_to_float( c );
|
|
|
|
return f.f;
|
|
|
|
}
|
|
|
|
|
2010-05-27 23:19:24 +00:00
|
|
|
} // nv namespace
|
|
|
|
|
|
|
|
#endif // NV_MATH_HALF_H
|