diff options
author | Wilson P. Snyder II <unknown@perl.org> | 1998-11-30 00:00:00 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 1998-12-31 11:18:17 +0000 |
commit | c8d591ab0c91c7e5b779c21585fd5e0c1d533c42 (patch) | |
tree | d61c839a9780269b7b0766bad2487e8053caa5fd /util.c | |
parent | b9ad3197a9434e67c559083718aa70fd38566318 (diff) | |
download | perl-c8d591ab0c91c7e5b779c21585fd5e0c1d533c42.tar.gz |
REV2: Binary number support
To: perl5-porters@perl.org
Message-ID: <199811301543.KAA15689@vulcan.maker.com>
p4raw-id: //depot/cfgperl@2546
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -2395,6 +2395,29 @@ same_dirent(char *a, char *b) #endif /* !HAS_RENAME */ UV +scan_bin(char *start, I32 len, I32 *retlen) +{ + register char *s = start; + register UV retval = 0; + bool overflowed = FALSE; + while (len && *s >= '0' && *s <= '1') { + register UV n = retval << 1; + if (!overflowed && (n >> 1) != retval) { + warn("Integer overflow in binary number"); + overflowed = TRUE; + } + retval = n | (*s++ - '0'); + len--; + } + if (len && (*s >= '2' || *s <= '9')) { + dTHR; + if (ckWARN(WARN_UNSAFE)) + warner(WARN_UNSAFE, "Illegal binary digit ignored"); + } + *retlen = s - start; + return retval; +} +UV scan_oct(char *start, I32 len, I32 *retlen) { register char *s = start; |