From bug-octave-request at bevo dot che dot wisc dot edu Fri Feb 18 01:02:29 2000 Subject: hex-numbers and 0xd From: "John W. Eaton" To: Tuukka dot Sales at fmi dot fi Cc: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 18 Feb 2000 01:02:37 -0600 (CST) Bug report for Octave 2.0.16 configured for i386-pc-linux-gnu Description: ----------- octave thinks that 0xd = 14, which is wrong (0xd=13). error occurs every time, when user-typed hex-number contains digit d (eg. 0x003400d00) It doesn't occur in statements of type [0x0:0xf] where d isn't typed explicitly. Repeat-By: --------- Statements: octave:1> 0xd ans = 14 or octave:2> 0x003400d ans = 213006 Please try the following patch. Thanks, jwe 2000-02-13 John W. Eaton * octMakefile.in (install): Install config.h in $(octincludedir)/octave. (DIRS_TO_MAKE): Create $(octincludedir)/octave. *** src/lex.l~ Tue Nov 2 00:36:16 1999 --- src/lex.l Fri Feb 18 01:01:01 2000 *************** *** 1400,1425 **** static void handle_number (char *yytext) { - char *tmp = strsave (yytext); - - char *idx = strpbrk (tmp, "Dd"); - - if (idx) - *idx = 'e'; - double value = 0.0; int nread = 0; ! if (looks_like_hex (tmp, strlen (tmp))) { unsigned long ival; nread = sscanf (tmp, "%lx", &ival); value = static_cast (ival); } else ! nread = sscanf (tmp, "%lf", &value); ! delete [] tmp; // If yytext doesn't contain a valid number, we are in deep doo doo. --- 1400,1429 ---- static void handle_number (char *yytext) { double value = 0.0; int nread = 0; ! if (looks_like_hex (idx, strlen (tmp))) { unsigned long ival; + nread = sscanf (tmp, "%lx", &ival); + value = static_cast (ival); } else ! { ! char *tmp = strsave (yytext); ! ! char *idx = strpbrk (tmp, "Dd"); ! ! if (idx) ! *idx = 'e'; ! nread = sscanf (tmp, "%lf", &value); ! ! delete [] tmp; ! } // If yytext doesn't contain a valid number, we are in deep doo doo. ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------