Source/astc_image_load_store.cpp
float float_to_lns(float p)
{
	if (astc::isnan(p) || p <= 1.0f / 67108864.0f)
	{
		// underflow or NaN value, return 0.
		// We count underflow if the input value is smaller than 2^-26.
		return 0;
	}

	if (fabsf(p) >= 65536.0f)
	{
		// overflow, return a +INF value
		return 65535;
	}

	int expo;
	float normfrac = frexpf(p, &expo);
	float p1;
	if (expo < -13)
	{
		// input number is smaller than 2^-14. In this case, multiply by 2^25.
		p1 = p * 33554432.0f;
		expo = 0;
	}
	else
	{
		expo += 14;
		p1 = (normfrac - 0.5f) * 4096.0f;
	}

	if (p1 < 384.0f)
		p1 *= 4.0f / 3.0f;
	else if (p1 <= 1408.0f)
		p1 += 128.0f;
	else
		p1 = (p1 + 512.0f) * (4.0f / 5.0f);

	p1 += expo * 2048.0f;
	return p1 + 1.0f;
}
// conversion functions between the LNS representation and the FP16 representation.
conversion functions between the LNS representation and the FP16 representation.
conversion functions between the LNS representation and the FP16 representation .
float float_to_lns(float p)
{
	if (astc::isnan(p) || p <= 1.0f / 67108864.0f)
	{
		return 0;
	}
	if (fabsf(p) >= 65536.0f)
	{
		return 65535;
	}
	int expo;
	float normfrac = frexpf(p, &expo);
	float p1;
	if (expo < -13)
	{
		p1 = p * 33554432.0f;
		expo = 0;
	}
	else
	{
		expo += 14;
		p1 = (normfrac - 0.5f) * 4096.0f;
	}
	if (p1 < 384.0f)
		p1 *= 4.0f / 3.0f;
	else if (p1 <= 1408.0f)
		p1 += 128.0f;
	else
		p1 = (p1 + 512.0f) * (4.0f / 5.0f);
	p1 += expo * 2048.0f;
	return p1 + 1.0f;
}
float float_to_lns ( float p ) { if ( astc :: isnan ( p ) || p <= 1.0f / 67108864.0f ) { return 0 ; } if ( fabsf ( p ) >= 65536.0f ) { return 65535 ; } int expo ; float normfrac = frexpf ( p , & expo ) ; float p1 ; if ( expo < -13 ) { p1 = p * 33554432.0f ; expo = 0 ; } else { expo += 14 ; p1 = ( normfrac - 0.5f ) * 4096.0f ; } if ( p1 < 384.0f ) p1 *= 4.0f / 3.0f ; else if ( p1 <= 1408.0f ) p1 += 128.0f ; else p1 = ( p1 + 512.0f ) * ( 4.0f / 5.0f ) ; p1 += expo * 2048.0f ; return p1 + 1.0f ; }
conversion functions between the LNS representation and the FP16 representation.
conversion functions between the LNS representation and the FP16 representation .
// underflow or NaN value, return 0. // We count underflow if the input value is smaller than 2^-26. // overflow, return a +INF value // input number is smaller than 2^-14. In this case, multiply by 2^25.