Coder Social home page Coder Social logo

jeaiii / itoa Goto Github PK

View Code? Open in Web Editor NEW
206.0 11.0 10.0 1.03 MB

Fast integer to ascii / integer to string conversion

License: MIT License

C++ 100.00%
itoa integer-conversion performance cpp ascii string-conversion single-header zero-dependency header-only

itoa's Introduction

Hi there πŸ‘‹

itoa's People

Contributors

jeaiii avatar syoyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

itoa's Issues

Versions for uint8_t, int8_t, uint16_t and int16_t

This is a fantastic, really fast algorithm, that even seems to beat Vitaut's. Many thanks for making this available.

My issue is actually a feature request. For completion, do you think that beyond the currently available implementations for uint32_t, int32_t, uint64_t and int64_t, would it be possible to add, in the future, implementations also for uint8_t, int8_t, uint16_t and int16_t?

It would be amazing to have those, for really fast conversion of low-latency batches of data.

GCC warning due to ASCII art

The ASCII art on "to_text_from_integer.h" generates a compiler warning with GCC 8:

itoa/to_text_from_integer.h:39:1: warning: multi-line comment [-Wcomment]
 //    /\   \     \     \     \
 ^

If you comment that line on the header file you also get a warning on the next one. I think it is due to the use of the character "\".

warnings emitted by msvc

When compiling with MSVC I'm getting warnings:
jeaiii_to_text.h(147): warning C4305: '/=': truncation from 'jeaiii::u32' to 'U'
jeaiii_to_text.h(209): warning C4305: '/=': truncation from 'jeaiii::u32' to 'U'

Replacing

n /= u32(1e8);

by

n = U(n /u32(1e8));

solves it.

Clang missing-braces

There is an warning from Clang 6.

itoa_jeaiii.cpp:65:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
static const pair s_pairs[] = { P('0'), P('1'), P('2'), P('3'), P('4'), P('5'), P('6'), P('7'), P('8'), P('9') };
                                ~~^~~~
                                {
itoa_jeaiii.cpp:64:14: note: expanded from macro 'P'
#define P(T) T, '0',  T, '1', T, '2', T, '3', T, '4', T, '5', T, '6', T, '7', T, '8', T, '9'
             ^~~~~~

Clarify roles of the two implementations

Just found this library and am quite surprised by how much of a performance improvement it made for our project!

However, while the interface of the functions is indeed so simple as to be mostly self explanatory, I am unsure about the roles of itoa_jeaiii.cpp and to_chars.cpp, i.e. which one to choose when, seeing that they basically offer the same functionality...

Thanks!

Features: zero-padding and fixed-point

I wanted to see how hard it might be to extend this to get fixed length zero-padded responses.

The other use-case is slightly less common but it can be often helpful to represent a fixed-point decimal number with a standard integer type like int32_t or int64_t where the number is stored as N * 10^D where D is the number of decimal digits supported. I was trying to think of how one could utilize your same approach but with the added issue of inserting the decimal place and potentially having leading zeros after the decimal but before the first digit.

Finally there is the fixed length, fixed-point decimal number, where you want to render the same number fixed-point decimal number but with a fixed number of decimal places and zero padding in the front for the rest

Mostly just thoughts on how this could be extended, I could provide naΓ―ve solutions to each of these if its helpful

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.