static inline MiF32        GetFloatValue(const char *str,const char **next)
{
	MiF32 ret = 0;

	if ( next ) *next = 0;

	str = SkipWhitespace(str);

	char dest[MAXNUM];
	char *dst = dest;
	const char *hex = 0;

	for (MiI32 i=0; i<(MAXNUM-1); i++)
	{
		char c = *str;
		if ( c == 0 || IsWhitespace(c) )
		{
			if ( next ) *next = str;
			break;
		}
		else if ( c == '$' )
		{
			hex = str+1;
		}
		*dst++ = ToLower(c);
		str++;
	}

	*dst = 0;

	if ( hex )
	{
		MiU32 iv = GetHEX(hex,0);
		MiF32 *v = (MiF32 *)&iv;
		ret = *v;
	}
	else if ( dest[0] == 'f' )
	{
		if ( strcmp(dest,"fltmax") == 0 || strcmp(dest,"fmax") == 0 )
		{
			ret = FLT_MAX;
		}
		else if ( strcmp(dest,"fltmin") == 0 || strcmp(dest,"fmin") == 0 )
		{
			ret = FLT_MIN;
		}
	}
	else if ( dest[0] == 't' ) // t or 'true' is treated as the value '1'.
	{
		ret = 1;
	}
	else
	{
		ret = (MiF32)atof(dest);
	}
	return ret;
}
Example #2
0
static inline float	GetFloatValue(const	char *str, const char	**next)
{
	float	ret	=	0;

	if ( str )
	{
		if (next)
		{
			*next	=	0;
		}

		str	=	SkipWhitespace(str);

		char dest[MAXNUM];
		char *dst	=	dest;
		const	char *hex	=	0;

		for	(int i = 0;	i	<	(MAXNUM	-	1);	i++)
		{
			char c =	*str;
			if (c	== 0 ||	IsWhitespace(c))
			{
				if (next)
				{
					*next	=	str;
				}
				break;
			}
			else if	(c ==	'$')
			{
				hex	=	str	+	1;
			}
			*dst++ = ToLower(c);
			str++;
		}

		*dst = 0;

		if (hex)
		{
			unsigned int iv	=	GetHEX(hex,	0);
			float	*v = (float*)	&iv;
			ret	=	 *v;
		}
		else if	(dest[0] ==	'f')
		{
			if (strcasecmp(dest,	"fltmax")	== 0 ||	strcasecmp(dest,	"fmax")	== 0 ||	strcasecmp(dest,	"FLT_MAX") ==	0	|| strcasecmp(dest, "INF")	== 0)
			{
				ret	=	FLT_MAX;
			}
			else if	(strcasecmp(dest, "fltmin") ==	0	|| strcasecmp(dest, "fmin") ==	0	|| strcasecmp(dest, "FLT_MIN")	== 0 ||	strcasecmp(dest,	"-INF")	== 0)
			{
				ret	=	-FLT_MAX;
			}
		}
		else if	(dest[0] ==	't')
		// t or	'true' is	treated	as the value '1'.
		{
			ret	=	1;
		}
		else
		{
			ret	=	(float)atof(dest);
		}
	}
	return ret;
}