MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / int2half

Function int2half

include/half_float/half.hpp:1076–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1074 /// \exception FE_OVERFLOW on overflows
1075 /// \exception FE_INEXACT if value had to be rounded
1076 template<std::float_round_style R,typename T> unsigned int int2half(T value)
1077 {
1078 unsigned int bits = static_cast<unsigned>(value<0) << 15;
1079 if(!value)
1080 return bits;
1081 if(bits)
1082 value = -value;
1083 if(value > 0xFFFF)
1084 return overflow<R>(bits);
1085 unsigned int m = static_cast<unsigned int>(value), exp = 24;
1086 for(; m<0x400; m<<=1,--exp) ;
1087 for(; m>0x7FF; m>>=1,++exp) ;
1088 bits |= (exp<<10) + m;
1089 return (exp>24) ? rounded<R,false>(bits, (value>>(exp-25))&1, (((1<<(exp-25))-1)&value)!=0) : bits;
1090 }
1091
1092 /// Convert half-precision to IEEE single-precision.
1093 /// Credit for this goes to [Jeroen van der Zijp](ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected