You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The is_str_num() function in string_stocks.inc currently does not handle negative numbers. The function only checks for the presence of digits in the string, without considering a leading negative sign which may be useful in some cases and that makes the function name misleading.
Updating is_str_num() may affect any existing code that relies on that behaviour, so maybe a new stock like is_str_num_ex() would be needed or a new optional parameter to allow negative numbers check. A note warning about this would be useful too.
Proposed fix
stockbool:is_str_num_ex(const sString[]) {
new i =0;
newbool:is_negative =false;
if (sString[0] =='-') {
is_negative =true;
i++;
}
while (sString[i] &&isdigit(sString[i])) {
i++;
}
return sString[i] ==0&& i != (is_negative ?1:0);
}
Call it parse_int, make it have a bool return and optional int outparam?On Aug 7, 2024 2:08 PM, rtxa ***@***.***> wrote:
The is_str_num() function in string_stocks.inc currently does not handle negative numbers. The function only checks for the presence of digits in the string, without considering a leading negative sign which may be useful in some cases and that makes the function name misleading.
Updating is_str_num() may affect any existing code that relies on that behaviour, so maybe a new stock like is_str_num_ex() would be needed or a new optional parameter to allow negative numbers check. A note warning about this would be useful too.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
Call it parse_int, make it have a bool return and optional int outparam
Already exists str_to_num() but you can't rely on it because it returns 0 on failure, and the input string can be a 0, unless we check that the string first digit isn't a 0.
The
is_str_num()
function instring_stocks.inc
currently does not handle negative numbers. The function only checks for the presence of digits in the string, without considering a leading negative sign which may be useful in some cases and that makes the function name misleading.Updating
is_str_num()
may affect any existing code that relies on that behaviour, so maybe a new stock likeis_str_num_ex()
would be needed or a new optional parameter to allow negative numbers check. A note warning about this would be useful too.Proposed fix
Test code:
Output:
The text was updated successfully, but these errors were encountered: