[Bug 3878] New: implementation of strtol/strtod in bg_lib.c
bugzilla-daemon at icculus.org
bugzilla-daemon at icculus.org
Thu Nov 27 19:16:18 EST 2008
http://bugzilla.icculus.org/show_bug.cgi?id=3878
Summary: implementation of strtol/strtod in bg_lib.c
Product: Quake 3
Version: SVN HEAD
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P3
Component: Misc
AssignedTo: zakk at icculus.org
ReportedBy: bugzilla at benmachine.co.uk
QAContact: quake3-bugzilla at icculus.org
atoi() is a pretty easy-to-use function, but it's also not very informative.
You get one integer back and that's it.
My man page for atoi recommended strtol() and strtod(), which provide greater
functionality and error-checking. They're less useful than in libc, because
errno doesn't exist, but regardless I thought they would be useful, so I
implemented them in bg_lib.c
I'm about to attach a patch for:
long strtol( const char *nptr, const char **endptr, int base );
which skips initial whitespace in nptr and performs a conversion of the
following string in the base given, which can be 2 to 36 or the special value
0, which is equivalent to 16 if the string starts with 0x, 8 if the string
starts with 0, or 10 otherwise. The conversion will not overflow: it will be
limited at LONG_MIN or LONG_MAX. *endptr is set to the character after the last
used in the conversion, which will be the value of nptr if no conversion was
possible.
double strtod( const char *nptr, const char **endptr );
similar to the above, parses a floating-point number in decimal, or hexadecimal
if the string starts with 0x. Special string values like inf and nan(0x7fffff)
are supported, along with exponents: in the decimal form, 5.2e8 means 5.2 times
ten to the power of eight; in hexadecimal 0x7f8p20 means 0x7f8 times 2 to the
power of 20 (oddly, the exponent is decimal, so this is twenty and not 32).
I tested this a little, but due to issues like bug 3718 it's not too easy to
stress-test a floating-point parser. I realise the code style is a little bit
strange at times, but I've been sitting on this for a while now and I think it
needs feedback before I can really improve it further.
--
Configure bugmail: http://bugzilla.icculus.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.
More information about the quake3-bugzilla
mailing list