-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast_convert.h
240 lines (218 loc) · 5.11 KB
/
fast_convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* Copyright 2019 Herman ten Brugge
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
#ifndef __FAST_STDIO_H
#define __FAST_STDIO_H
#include <inttypes.h>
#if defined (__cplusplus)
extern "C"
{
#endif
/* See: https://en.wikipedia.org/wiki/IEEE_754#2019 */
#define PREC_FLT_NR 9
#define PREC_DBL_NR 17
#define PREC_FLT "9"
#define PREC_DBL "17"
/** \brief fast_sint32
*
* \b Description
*
* Convert signed integer to string
*
* \param v Integer
* \param str Buffer to print to
* \returns lenght string
*/
extern unsigned int fast_sint32 (int32_t v, char *str);
/** \brief fast_sint64
*
* \b Description
*
* Convert signed long integer to string
*
* \param v Long integer
* \param str Buffer to print to
* \returns lenght string
*/
extern unsigned int fast_sint64 (int64_t v, char *str);
/** \brief fast_uint32
*
* \b Description
*
* Convert unsigned integer to string
*
* \param v Integer
* \param str Buffer to print to
* \returns lenght string
*/
extern unsigned int fast_uint32 (uint32_t v, char *str);
/** \brief fast_uint64
*
* \b Description
*
* Convert unsigned long integer to string
*
* \param v Long integer
* \param str Buffer to print to
* \returns lenght string
*/
extern unsigned int fast_uint64 (uint64_t v, char *str);
/** \brief fast_base_sint32
*
* \b Description
*
* Convert signed integer to string with base and upper case
*
* \param v Integer
* \param str Buffer to print to
* \param base Base to use
* \param upper Use uppecase
* \returns lenght string
*/
extern unsigned int fast_base_sint32 (int32_t v, char *str, int base,
int upper);
/** \brief fast_base_sint64
*
* \b Description
*
* Convert signed long integer to string with base and upper case
*
* \param v Long integer
* \param str Buffer to print to
* \param base Base to use
* \param upper Use uppecase
* \returns lenght string
*/
extern unsigned int fast_base_sint64 (int64_t v, char *str, int base,
int upper);
/** \brief fast_uint32
*
* \b Description
*
* Convert unsigned base_integer to string with base and upper case
*
* \param v Integer
* \param str Buffer to print to
* \param base Base to use
* \param upper Use uppecase
* \returns lenght string
*/
extern unsigned int fast_base_uint32 (uint32_t v, char *str, int base,
int upper);
/** \brief fast_base_uint64
*
* \b Description
*
* Convert unsigned long integer to string with base and upper case
*
* \param v Long integer
* \param str Buffer to print to
* \param base Base to use
* \param upper Use uppecase
* \returns lenght string
*/
extern unsigned int fast_base_uint64 (uint64_t v, char *str, int base,
int upper);
/** \brief fast_strtos32
*
* \b Description
*
* Convert string to signed integer
*
* \param str String to convert from
* \param endptr optional endptr
* \param base base of converting.
* \returns converted string
*/
extern int32_t fast_strtos32 (const char *str, char **endptr, int base);
/** \brief fast_strtos64
*
* \b Description
*
* Convert string to signed long
*
* \param str String to convert from
* \param endptr optional endptr
* \param base base of converting.
* \returns converted string
*/
extern int64_t fast_strtos64 (const char *str, char **endptr, int base);
/** \brief fast_strtou32
*
* \b Description
*
* Convert string to unsigned int
*
* \param str String to convert from
* \param endptr optional endptr
* \param base base of converting.
* \returns converted string
*/
extern uint32_t fast_strtou32 (const char *str, char **endptr, int base);
/** \brief fast_strtou64
*
* \b Description
*
* Convert string to unsigned long
*
* \param str String to convert from
* \param endptr optional endptr
* \param base base of converting.
* \returns converted string
*/
extern uint64_t fast_strtou64 (const char *str, char **endptr, int base);
/** \brief fast_ftoa
*
* \b Description
*
* Convert float to ascii
*
* \param v float value
* \param size precision
* \param line pointer to result
* \returns lenght string
*/
extern unsigned int fast_ftoa (float v, int size, char *line);
/** \brief fast_dtoa
*
* \b Description
*
* Convert double to ascii
*
* \param v float value
* \param size precision
* \param line pointer to result
* \returns lenght string
*/
extern unsigned int fast_dtoa (double v, int size, char *line);
/** \brief fast_strtof
*
* \b Description
*
* Convert string to float
*
* \param str string to convert
* \param endptr optional endptr
* \returns converted float value
*/
extern float fast_strtof (const char *str, char **endptr);
/** \brief fast_strtod
*
* \b Description
*
* Convert string to double
*
* \param str string to convert
* \param endptr optional endptr
* \returns converted double value
*/
extern double fast_strtod (const char *str, char **endptr);
#if defined (__cplusplus)
}
#endif
#endif /* __FAST_STDIO_H */