Giter VIP home page Giter VIP logo

strtod's Introduction

Custom strtod implementation

A custom implementation of strtod which functions very similar to the standard C strtod function with some minor differences:

  1. this function skips over underscores to allow for underscore seperated numbers
  2. by default, errno is not set to ERANGE when the normalized value of the number would be less tha DBL_MIN but is instead set if the resulting double would be 0 where the value is not 0. (see below)
  3. where strtod can check for the 0x prefix tp parse hexadecimals, c8_strToD does not by default. this behavior can optionally be enabled with a compiler flag. (see below)
  4. when enabled c8_strToD checks for any prefix (0x, 0o, 0b) and calls c8_strToLL.
    1. Note that this is not the same behavior strtod does. strtod only seems to handle prefixes 0x and 0X. Also a number 0x will be consumed as 0 with x remaining while c8_strToLL would not consume any bit of that number at all.

There may be more inconsistancies. These are the minor ones due to design, simplicity, or what I have found through testing...

Options

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.