jeaiii / itoa Goto Github PK
View Code? Open in Web Editor NEWFast integer to ascii / integer to string conversion
License: MIT License
Fast integer to ascii / integer to string conversion
License: MIT License
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.
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 "\".
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.
I just merged MoarVM/MoarVM#1618 which uses this implementation. Thought you might like to know, thanks for this!
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'
^~~~~~
itoa/include/itoa/jeaiii_to_text.h
Line 150 in 84f25b8
all 9 digits numbers should be handled above (and ~4/10ths of the 10 digits numbers) so this should be like:
itoa/include/itoa/jeaiii_to_text.h
Lines 209 to 213 in 84f25b8
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!
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
This failed to convert this number: 3890001770327310336.
This resulted in 3890001770227310336 (Diff of 10'000'000)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.