Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scan_number in string_utilities.cc should permit rational numbers, i.e. those with a decimal point. #198

Open
mholtrop opened this issue Mar 22, 2021 · 3 comments

Comments

@mholtrop
Copy link
Contributor

Error is in the updated code. Corrected code, string_utilities.cc:54 is:

{
	// Scan the c_string str for numbers only, then return the value as a float.
	// The str is not allowed to have spaces or alphanumerics, only 0-9 and .
	int i=0;
// 	while(char c=str[i++]) if((isalpha(c) || ispunct(c) || iscntrl(c) || isspace(c)) && !(c=='-' || c=='+' || c=='e' || c=='E') )
	while(char c=str[i++]) if(!(isdigit(c) || c=='-' || c=='+' || c=='e' || c=='E' || c=='.'))
	{
		cout << "WARNING: Unexpected character found in number string: " << str << endl;
		cout << "Exiting " << endl; exit(1);
	}
	return( stringToDouble(str));
}
@mholtrop
Copy link
Contributor Author

Humbug. Seems:

{

	// Scan the c_string str for numbers only, then return the value as a float.
	// The str is not allowed to have spaces or alphanumerics, only 0-9 and .
	int i=0;
	while(char c=str[i++]) if(isalpha(c) && !(c=='-' || c=='+' || c=='e' || c=='E') )
	{
		cout << "WARNING: Unexpected Alphanumberic character found in number string:" << str << endl;
	}

	return( stringToDouble(str));

}

works as well. (Updated code a few hours ago.)

@zhaozhiwen
Copy link
Contributor

this doesn't work when for "8,3e3" where "," is a mistake for "."
while(char c=str[i++]) if(isalpha(c) && !(c=='-' || c=='+' || c=='e' || c=='E') )

this works better
while(char c=str[i++]) if(!(isdigit(c) || c=='-' || c=='+' || c=='e' || c=='E' || c=='.'))

Mauri, can you fix this bug?

@mholtrop mholtrop reopened this Mar 22, 2021
@mholtrop
Copy link
Contributor Author

Ah yes, thanks Zhiwen, that would be data entries by our European collaborators (where . is exchanged with , in numbers sometimes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants