[PATCH v5 2/3] cmdline: add floating point support

Burakov, Anatoly anatoly.burakov at intel.com
Fri May 23 12:21:15 CEST 2025


On 5/21/2025 4:05 PM, Stephen Hemminger wrote:
> On Wed,  7 May 2025 16:22:11 +0100
> Anatoly Burakov <anatoly.burakov at intel.com> wrote:
> 
>> +NUMERIC_TYPES = {
>> +    "UINT8": "uint8_t",
>> +    "UINT16": "uint16_t",
>> +    "UINT32": "uint32_t",
>> +    "UINT64": "uint64_t",
>> +    "INT8": "int8_t",
>> +    "INT16": "int16_t",
>> +    "INT32": "int32_t",
>> +    "INT64": "int64_t",
>> +    "FLOAT_SINGLE": "float",
>> +    "FLOAT_DOUBLE": "double",
>> +}
>>   
> 
> Is it really worth having both single and double versions.
> Seems like unnecessary complexity at this point.

I'd argue the same about the various int types. I was just being 
consistent. I can remove the single (or double) if that's desired.

> 
>> @@ -291,6 +302,25 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
>>   			return -1;
>>   		}
>>   		return ret;
>> +	/* float parsing */
>> +	} else if (nd.type >= RTE_FLOAT_SINGLE && nd.type <= RTE_FLOAT_DOUBLE) {
>> +		char *end;
>> +		double dres = strtod(srcbuf, &end);
>> +
>> +		if (end == srcbuf || !cmdline_isendoftoken(*end) || isinf(dres))
>> +			return -1;
>> +
>> +		/* we parsed something, now let's ensure it fits */
>> +		if (nd.type == RTE_FLOAT_SINGLE) {
>> +			float flt = (float)dres;
>> +			if (isinf(flt))
>> +				return -1;
>> +			if (res) *(float *)res = flt;
>> +			return end-srcbuf;
>> +		} else if (nd.type == RTE_FLOAT_DOUBLE) {
>> +			if (res) *(double *)res = dres;
>> +			return end-srcbuf;
> 
> Space around - please


-- 
Thanks,
Anatoly


More information about the dev mailing list