towards a faster isdigit()

P E Smee exspes at gdr.bath.ac.uk
Thu May 9 02:45:42 AEST 1991


In article <1991May8.163547.21677 at gdr.bath.ac.uk> P.Smee at bristol.ac.uk (Paul Smee) writes:
>In article <1991May8.030515.7004 at twinsun.com> eggert at twinsun.com (Paul Eggert) writes:
>>The traditional implementation of isdigit() in <ctype.h> is typically
>>something like this:
>>
>>	#define isdigit(c) ((_ctype_+1)[c] & 4)
>>
>>which requires indexing through a global array followed by a masking
>>operation.  Why not use the following implementation instead?
>>
>>	#define isdigit(c) ((unsigned)((c)-'0') < 10)
>>
>>This needs just a subtraction followed by a comparison.  It's faster on
>>all the systems I've tried it on, and is strictly conforming ANSI C.
>
>And, it works just fine, if you believe that the chars /.-,+*()' are
>digits.  :-)

Silly me.  Ignore that, if it gets to your site before I manage to cancel
it.  My excuse is simply that I've been in too long today, sigh...

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee at bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132



More information about the Comp.lang.c mailing list