Affix
view release on metacpan or search on metacpan
lib/Affix/marshal.c view on Meta::CPAN
return (sign) ? -0.0f : 0.0f; /* Signed zero */
while (!(h_sig & 0x400)) { /* Subnormal number: normalize it */
h_sig <<= 1;
h_exp--;
}
h_exp++;
h_sig &= ~0x400;
}
else if (h_exp == 0x1f) {
/* Infinity or NaN */
uint32_t f_nan = (h_sig == 0) ? 0x7f800000 : 0x7fc00000;
union {
uint32_t u;
float f;
} u;
u.u = sign | f_nan;
return u.f;
}
/* Adjust exponent bias from 15 to 127 and align mantissa to 23 bits */
uint32_t f_exp = (h_exp + (127 - 15)) << 23;
lib/Affix/marshal.c view on Meta::CPAN
*/
float16_t float32_to_float16(float f) {
union {
float f;
uint32_t u;
} u;
u.f = f;
uint32_t sign = (u.u >> 16) & 0x8000;
uint32_t exp = (u.u >> 23) & 0xff;
uint32_t sig = u.u & 0x7fffff;
/* Handle Inf and NaN */
if (exp == 0xff)
return sign | 0x7c00 | (sig ? 0x200 : 0);
int e = (int)exp - 127 + 15; /* Re-bias exponent to 15 */
if (e >= 31)
return sign | 0x7c00; /* Overflow to Infinity */
if (e <= 0) {
/* Underflow to Subnormal */
if (e < -10)
return sign;
sig |= 0x800000;
( run in 1.299 second using v1.01-cache-2.11-cpan-2c0d6866c4f )