www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - isNumeric in Phobos(D1&D2) seems bugged

reply badmadevil <badmadevil gmail.com> writes:
============================= isnum.d
import std.stdio ;
import std.string ;
void main(string[] args) {
  for(int i = 1 ; i< args.length ; i++)
    writefln("\"%s\" is%s a numeric.", args[i], isNumeric(args[i], true)? "": "
not") ;
}
============================= output
isnum.exe 9.9e+99 99e+9.9 9.9e+9.9
"9.9e+99" is a numeric. "99e+9.9" is a numeric. "9.9e+9.9" is not a numeric. The last one should give affirmative.
Feb 11 2008
parent reply Sergey Gromov <snake.scaly gmail.com> writes:
badmadevil <badmadevil gmail.com> wrote:
 ============================= isnum.d
 import std.stdio ;
 import std.string ;
 void main(string[] args) {
   for(int i = 1 ; i< args.length ; i++)
     writefln("\"%s\" is%s a numeric.", args[i], isNumeric(args[i], true)? "":
" not") ;
 }
 ============================= output
isnum.exe 9.9e+99 99e+9.9 9.9e+9.9
"9.9e+99" is a numeric. "99e+9.9" is a numeric. "9.9e+9.9" is not a numeric. The last one should give affirmative.
Yes, I think there is a bug, too. Though not where you're pointing it out. D doesn't support fractional exponents. This means that both "99e+9.9" and "9.9e+9.9" are not numbers. -- SnakE
Feb 11 2008
parent badmadevil <badmadevil gmail.com> writes:
Sergey Gromov wrote:
 badmadevil <badmadevil gmail.com> wrote:
 ============================= isnum.d
 import std.stdio ;
 import std.string ;
 void main(string[] args) {
   for(int i = 1 ; i< args.length ; i++)
     writefln("\"%s\" is%s a numeric.", args[i], isNumeric(args[i], true)? "":
" not") ;
 }
 ============================= output
 isnum.exe 9.9e+99 99e+9.9 9.9e+9.9
"9.9e+99" is a numeric. "99e+9.9" is a numeric. "9.9e+9.9" is not a numeric. The last one should give affirmative.
Yes, I think there is a bug, too. Though not where you're pointing it out. D doesn't support fractional exponents. This means that both "99e+9.9" and "9.9e+9.9" are not numbers.
ic, i check these strings with ruby eval() function by if exception raise, and give last 2 non-numeric. But, I also check if 9.9e99 (vs 9.9e+99)is numeric. In ruby, it is numeric; in D isNumeric, it is not. However, to!(real)("9.9e99") give 9.9e+99. ie. in D
 isnum2 9.9e99 99e9.9 9.9e9.9
"9.9e99" is not a numeric(9.9e+99). "99e9.9" is not a numeric<conv error>. "9.9e9.9" is not a numeric<conv error>.
Feb 11 2008