A custom implementation of strtod
which functions very similar to the standard C strtod
function with some minor differences:
- this function skips over underscores to allow for underscore seperated numbers
- by default,
errno
is not set toERANGE
when the normalized value of the number would be less thaDBL_MIN
but is instead set if the resulting double would be 0 where the value is not 0. (see below) - where
strtod
can check for the0x
prefix tp parse hexadecimals,c8_strToD
does not by default. this behavior can optionally be enabled with a compiler flag. (see below) - when enabled
c8_strToD
checks for any prefix (0x
,0o
,0b
) and callsc8_strToLL
.- Note that this is not the same behavior
strtod
does.strtod
only seems to handle prefixes0x
and0X
. Also a number0x
will be consumed as0
withx
remaining whilec8_strToLL
would not consume any bit of that number at all.
- Note that this is not the same behavior
There may be more inconsistancies. These are the minor ones due to design, simplicity, or what I have found through testing...
There are some togglable options to change the parsers behavior. they can be enabled with define
's. Here are some options and what they do:
Option | Description | Examples |
---|---|---|
USE_STRTOLL_FOR_PREFIX |
Allows the parser to to send numbers beginning with 0x , 0o , and 0b to c8_strToLL to parse as a number of a different base. (note that this is currently included using a relative path) |
numbers like 0xABCDEF , 0x10101 , and 0o1234567 will be parsed |
USE_DEFAULT_STRTOLL |
(depends on USE_STRTOLL_FOR_PREFIX to be enabled) sends numbers to the default C strtoll function instead of the custom one |
|
ERRNO_AT_DBL_MIN_AND_MAX |
Sets errno when a number whose normalized value is greater than DBL_MAX or less than DBL_MIN . |