[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
string-to-number
From: |
Nick Roberts |
Subject: |
string-to-number |
Date: |
Thu, 17 Nov 2005 17:20:02 +1300 |
Currently string-to-number gives 0 for a non-number:
(string-to-number "a")^J
0
but
(string-to-number "0")^J
0
gives the same result. So what is a simple test for whether a string
represents a number or not?
If there isn't one, how about:
(string-to-number "a")^J
nil
Of course this means an error is generated if you try to do arithmetic with a
non-number, but I think that this is appropriate and preferable to taking a
value of 0.
Nick
*** data.c 31 Oct 2005 00:56:53 +1300 1.256
--- data.c 17 Nov 2005 16:28:28 +1300
***************
*** 2466,2472 ****
register unsigned char *p;
register int b;
int sign = 1;
! Lisp_Object val;
CHECK_STRING (string);
--- 2466,2472 ----
register unsigned char *p;
register int b;
int sign = 1;
! Lisp_Object val = Qnil;
CHECK_STRING (string);
***************
*** 2506,2514 ****
if (digit < 0)
break;
v = v * b + digit;
}
! val = make_fixnum_or_float (sign * v);
}
return val;
--- 2506,2515 ----
if (digit < 0)
break;
v = v * b + digit;
+ val = Qt;
}
! if (!NILP (val)) val = make_fixnum_or_float (sign * v);
}
return val;
- string-to-number,
Nick Roberts <=