ISDIGIT(3)
π ISDIGIT(3) β the decimal-digit character test, bestie edition β¨
okay so this is page 3 of the manual, the ISDIGIT one β it's a libc thing, and it's honestly so much simpler than it looks. let's get into it π«Ά
πΈ NAME πΈ
isdigit, isnumber, isdigit_l, isnumber_l β the decimal-digit character test, aka "is this a digit or not, bestie?" π
π LIBRARY π
Standard C Library (libc, -lc) β the classic, the icon, the one you link with -lc π
β¨ SYNOPSIS β¨
okay so here's the vibe, write it exactly like this:
#include <ctype.h>
int
isdigit(int c);
int
isnumber(int c);
int
isdigit_l(int c, locale_t loc);
int
isnumber_l(int c, locale_t loc);
like, four little functions, all vibing in <ctype.h>, all taking an int and handing you back an int. the _l girlies take an extra locale_t loc because they're extra π
π¦ DESCRIPTION π¦
so isdigit() and isdigit_l() are out here testing whether a character is a decimal digit. and no cap β regardless of locale, that means literally only these characters, nothing else:
``0'' ``1''``2''``3''``4''
``5'' ``6''``7''``8''``9''
that's it. that's the whole list. 0 through 9, ten characters, periodt. π
then there's isnumber() and isnumber_l() β they behave similarly to isdigit() and isdigit_l(), but they might recognize additional characters, depending on your current locale setting. so they're like the same function but with β¨rangeβ¨. iykyk π§
β οΈ important vibe check: the value of the argument must be representable as anunsigned char, or it can be the value ofEOF. that's a hard requirement, not a suggestion, bestie π
and the _l-suffixed versions take an explicit locale argument, whereas the non-suffixed versions use the current global or per-thread locale. so the _l ones are the "i know exactly what locale i want" girls, and the plain ones are the "whatever the ambient locale is" girls. both valid π
π₯ RETURN VALUES π₯
isdigit()β returns zero if the character tests false, non-zero if it tests trueisdigit_l()β same deal, zero for false, non-zero for trueisnumber()β yep, zero for false, non-zero for trueisnumber_l()β you guessed it, zero for false, non-zero for true
so: zero = nope, non-zero = yep. that's the whole return value saga π
π COMPATIBILITY π
okay so this one's a lil messy. the 4.4BSD extension of accepting arguments outside of the range of the unsigned char type in locales with large character sets? considered obsolete and may not be supported in future releases. so like, don't get attached π
π¨ instead, useiswdigit()oriswdigit_l(). those are the ones you actually want. the old behavior is giving deprecated energy and it might just disappear on you one day β
π SEE ALSO π
go check out the whole friend group:
π STANDARDS π
isdigit()conforms to ISO/IEC 9899:1990 (βISO C90β) β old school, still iconicisdigit_l()conforms to IEEE Std 1003.1-2008 (βPOSIX.1β) β the modern queen
note that isnumber() and isnumber_l() are not in this list, which is lowkey a whole thing π
π HISTORY π
the isnumber() function appeared in 4.4BSD. that's it, that's the lore π
and that's the page, bestie! this was from the Debian crew, dated December 19, 2022 β thank you for coming to my ted talk, now go check your digits πβ¨ππ¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms