ISDIGIT(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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 an unsigned char, or it can be the value of EOF. 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 true
  • isdigit_l() β€” same deal, zero for false, non-zero for true
  • isnumber() β€” yep, zero for false, non-zero for true
  • isnumber_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, use iswdigit() or iswdigit_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 iconic
  • isdigit_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms