Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!mcsun!ukc!dcl-cs!gdt!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: towards a faster isdigit() Message-ID: <1991May8.164542.23084@gdr.bath.ac.uk> Date: 8 May 91 16:45:42 GMT References: <1991May8.030515.7004@twinsun.com> <1991May8.163547.21677@gdr.bath.ac.uk> Reply-To: P.Smee@bristol.ac.uk (Paul Smee) Organization: University of Bristol c/o University of Bath Lines: 24 In article <1991May8.163547.21677@gdr.bath.ac.uk> P.Smee@bristol.ac.uk (Paul Smee) writes: >In article <1991May8.030515.7004@twinsun.com> eggert@twinsun.com (Paul Eggert) writes: >>The traditional implementation of isdigit() in 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@bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132