towards a faster isdigit()

Stephen Clamage steve at taumet.com
Thu May 9 10:02:42 AEST 1991


I wrote:

|eggert at twinsun.com (Paul Eggert) writes:

|>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.

|Maybe you didn't try it on enough systems :-)

|The macro you suggest requires a test and jump, and on some modern RISC
|machines the penalty is very high.

Bruce Evans pointed out to me that since isdigit() is used in tests,
the test-and-jump is already paid for.  I checked my test code to 
see why I got the results I did, and found they were the opposite
of what I reported.  I'm sorry for wasting everyone's time with this.

Paul's macro is indeed faster.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list