Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!ucla-cs!twinsun!eggert From: eggert@twinsun.com (Paul Eggert) Newsgroups: comp.lang.c Subject: towards a faster isdigit() Message-ID: <1991May8.030515.7004@twinsun.com> Date: 8 May 91 03:05:15 GMT Sender: usenet@twinsun.com Organization: Twin Sun, Inc Lines: 12 Nntp-Posting-Host: ata 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.