-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathembedded_printf.c
More file actions
851 lines (754 loc) · 21.4 KB
/
embedded_printf.c
File metadata and controls
851 lines (754 loc) · 21.4 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/******************************************************************************
* Embedded version of "printf( )" function
* - with similar functions but more efficient
*
* author: Haroldo Amaral - agaelema@gmail.com
* v0.5 - 2017/08/20
*
* Based in this link:
* http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/30479/107146
******************************************************************************
* log: . change some "#ifdef" to "#if defined ( )"
******************************************************************************/
#include "embedded_printf.h"
#include "serial_conf.h"
#include <stdarg.h>
#include <stdint.h>
/******************************************************************************
* Call the specific function to send data
* Input: unsigned char byte (byte to be transmited)
* Output: none
******************************************************************************/
void putChar(uint8_t byte)
{
serial_sendbyte(byte);
}
void linesUp(unsigned int lines)
{
unsigned int i;
for (i = 0; i < lines; ++i)
{
putChar(0x1b);
putChar(0x5b);
putChar(0x41);
}
}
/******************************************************************************
* Print a String in the serial port
* input: char *string (string to be printed)
* unsigned int width (limit the pad size)
* unsigned int pad (control the padding)
* return: number of characters
******************************************************************************/
//int embedded_prints(char *string, unsigned int width, unsigned int pad)
unsigned int embedded_prints(char *string, unsigned int width, unsigned int pad)
{
unsigned int return_value = 0;
unsigned char padchar = ' ';
if (width > 0)
{
unsigned int len = 0; // string length
char *ptr;
for (ptr = string; *ptr; ++ptr) { // Calculate string length
++len;
}
if (len >= width) width = 0; // If string is longer than width
else width -= len;
#ifdef ENABLE_PAD_
if (pad & PAD_ZERO) padchar = '0';
#endif
}
#ifdef ENABLE_PAD_
if (!(pad & PAD_RIGHT)) // If not right padding - left justification
{
for (; width > 0; --width) // if padding is possible - put the char
{
putChar(padchar);
++return_value;
}
}
#endif
while (*string)
{
putChar(*string);
++return_value;
// *++string;
++string;
}
#ifdef ENABLE_PAD_
for (; width > 0; --width) {
putChar(padchar);
++return_value;
}
#endif
return return_value; // Return the number of characters printed
}
/******************************************************************************
* Print an integer number (signed or unsigned) with max size of 32bits (long)
* input: char *print_buf (pointer to the buffer when the string will be saved)
* signed long input (number to be printed - use the casting "(long)" before the number
* unsigned int base (base of number - decimal, hexa, binary)
* unsigned int sg (1 = signed, 0 = unsigned)
* unsigned int width (mas size of padding)
* unsigned int pad (control the padding)
* unsigned char letbase (base to select the character in the ASCII table)
* return: int return_value (number of characters printed - like standard printf)
******************************************************************************/
//int embedded_ltoa(char *print_buf, signed long input, unsigned int base, unsigned int sg, unsigned int width, unsigned int pad, unsigned char letbase)
unsigned int embedded_ltoa(char *print_buf, int32_t input, unsigned int base, unsigned int sg, unsigned int width, unsigned int pad, unsigned char letbase)
{
char *s;
char neg = 0;
uint32_t t;
uint32_t u = input;
unsigned int return_value = 0;
// if (input == 0)
// {
// if (base != 2)
// {
// print_buf[0] = '0';
// print_buf[1] = '\0'; // Always remenber to put string end
// return 2;
//// print_buf[(2 * label) + 0] = '0';
//// print_buf[(2 * label) + 1] = '\0'; // Always remenber to put string end
//// if ((label) && (base == HEXADEC))
//// {
//// print_buf[0] = '0';
//// print_buf[1] = 'x';
//// }
//// return ((2 * label) + 2);
// }
// else
// {
// unsigned int xx;
// for (xx = 0; xx < width; xx++)
// {
// print_buf[xx] = '0';
//// print_buf[(2 * label) + xx] = '0';
// }
// print_buf[width] = '\0';
//// print_buf[(2 * label) + width] = '\0';
//// if (label)
//// {
//// print_buf[0] = '0';
//// print_buf[1] = 'x';
//// }
// return (width + 1);
// }
// }
if (sg && (base == 10) && (input < 0)) // If it is a negative number in decimal base
{
neg = 1;
u = -input;
}
s = print_buf + PRINT_BUF_LEN - 1; // go to the end of buffer
*s = '\0'; // print the string terminator "\0"
do
{
if (base != 2) // if decimal or hexa
{
t = u % base;
if (t >= 10)
t += letbase - '0' - 10;
*--s = t + '0';
u /= base;
}
#ifdef ENABLE_BINARY_
else
{ // if binary
while (width)
{
*--s = (u & 0x01) ? '1' : '0';
u >>= 1;
width--;
}
u = 0;
}
#endif
}while(u);
// if (label) { // place the label... not implemented (some bugs)
// if (base != DECIMAL)
// {
// *--s = (base == HEXADEC ? 'x' : 'b');
// *--s = '0';
// }
// }
if (neg) // if negative, put the "-" signal
{
//// old version of code
// if (width && (pad & PAD_ZERO))
// { // If there is width, right justified and pad with zero, output negative sign.
// putChar('-');
// ++return_value;
// --width;
// }
// else *--s = '-'; // Otherwise put the '-' to string buffer.
if (!(width && (pad & PAD_ZERO)))
{
*--s = '-'; // Otherwise put the '-' to string buffer.
}
#ifdef ENABLE_PAD_
else // If there is width, right just. and pad with zero
{
putChar('-');
++return_value;
--width;
}
#endif
}
char *buffer_end = print_buf + PRINT_BUF_LEN - 1;
int count;;
// count = (int)buffer_end - (int)s;
count = (int)(buffer_end - s);
int xx;
for (xx = 0; xx < count + 1; xx++) {
print_buf[xx] = *s;
s++;
}
return return_value;
}
#ifdef ENABLE_FLOAT_
#ifdef PRECISION_FLOAT_
/******************************************************************************
* Print a float number (double)
* input: char *print_buf (pointer to the buffer when the string will be saved)
* double input (number to be printed - use the casting "(double)" before the number
* signed int dp (number of decimal places - between 1 and 4)
* unsigned int sci (1 = scientific, 0 = non scientific notation)
* return: unsigned int return_value (number of characters printed - like standard printf)
******************************************************************************/
//int embedded_ftoa(char *print_buf, double input, signed int dp, unsigned int sci)
unsigned int embedded_ftoa(char *print_buf, double input, signed int dp, unsigned int sci)
{
char *s;
unsigned int neg = 0;
uint32_t t;
int32_t integer;
#ifdef ENABLE_EXTRA_DECIMAL_PLACE_
uint64_t decimal;
#else
uint32_t decimal;
#endif
int Exp = 0;
int Exp_sg = 0;
// int return_value = 0;
unsigned int return_value = 0;
#ifdef ENABLE_EXTRA_DECIMAL_PLACE_
if (dp > 9) {dp = 9;}
#else
if (dp > 4) {dp = 4;}
#endif
if (dp < 1) {dp = 1;}
double number;
number = input;
if (number < 0) {
neg = 1;
number *= -1;
}
if (sci)
{
if (number >= 10)
{
while (number >= 10)
{
number /= 10;
Exp++;
}
}
if ((number < 1) && (number != 0))
{
while (number < 1)
{
number *= 10;
Exp--;
}
}
if (Exp < 0) {
Exp *= -1;
Exp_sg = 1;
}
}
integer = (int32_t)number;
number = number - (double)integer;
unsigned int ii;
#ifdef ENABLE_EXTRA_DECIMAL_PLACE_
uint32_t mult = 1;
#else
uint16_t mult = 1;
#endif
for (ii = 0; ii < dp; ++ii) { // calculate the multiplier to convert decimal in integer value with desired dp
mult *= 10;
}
decimal = (uint32_t)(number * (double)mult);
s = print_buf + PRINT_BUF_LEN - 1;
*s = '\0';
if (sci)
{
do
{
t = Exp % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
Exp /= 10;
}while(Exp);
if (Exp_sg) {
*--s = '-';
}
*--s = 'e';
}
while (dp) // convert the portion after the dot "."
{
t = decimal % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
decimal /= 10;
--dp;
}
*--s = '.'; // put the dot separator
do // convert the portion before the dot "."
{
t = integer % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
integer /= 10;
}while(integer);
if (neg) // if negative
{
// if (width && (pad & PAD_ZERO))
// { // If there is width, right justified and pad with zero, output negative sign.
// putChar('-');
// ++return_value;
// --width;
// }
// else *--s = '-';
*--s = '-';
}
// volatile int count;
int count;
count = s - print_buf;
int xx;
for (xx = 0; xx < count; xx++) { // the string is formed in the end of buffer
print_buf[xx] = *s; // this code move to the beginning
s++;
}
return return_value;
}
#else
/******************************************************************************
* Print a float number (float)
* input: char *print_buf (pointer to the buffer when the string will be saved)
* float input (number to be printed - use the casting "(float)" before the number
* signed int dp (number of decimal places - between 1 and 4)
* unsigned int sci (1 = scientific, 0 = non scientific notation)
* return: unsigned int return_value (number of characters printed - like standard printf)
******************************************************************************/
//int embedded_ftoa(char *print_buf, float input, signed int dp, unsigned int sci)
unsigned int embedded_ftoa(char *print_buf, float input, signed int dp, unsigned int sci)
{
char *s;
unsigned int neg = 0;
unsigned long t;
int32_t integer;
uint32_t decimal;
int Exp = 0;
int Exp_sg = 0;
unsigned int return_value = 0;
if (dp > 4) {dp = 4;}
if (dp < 1) {dp = 1;}
float number;
number = input;
if (number < 0) {
neg = 1;
number *= -1;
}
if (sci)
{
if (number >= 10)
{
while (number >= 10)
{
number /= 10;
Exp++;
}
}
if ((number < 1) && (number != 0))
{
while (number < 1)
{
number *= 10;
Exp--;
}
}
if (Exp < 0) {
Exp *= -1;
Exp_sg = 1;
}
}
integer = (int32_t)number;
number = number - (float)integer;
unsigned int ii;
unsigned int mult = 1;
for (ii = 0; ii < dp; ++ii) {
mult *= 10;
}
decimal = (uint32_t)(number * (float)mult);
s = print_buf + PRINT_BUF_LEN - 1;
*s = '\0';
if (sci)
{
do
{
t = Exp % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
Exp /= 10;
}while(Exp);
if (Exp_sg) {
*--s = '-';
}
*--s = 'e';
}
while (dp) // convert the portion after the dot "."
{
t = decimal % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
decimal /= 10;
--dp;
}
*--s = '.'; // put the dot separator
do // convert the portion before the dot "."
{
t = integer % 10;
if (t >= 10)
t += 'a' - '0' - 10;
*--s = t + '0';
integer /= 10;
}while(integer);
if (neg) // if negative
{
// if (width && (pad & PAD_ZERO))
// { // If there is width, right justified and pad with zero, output negative sign.
// putChar('-');
// ++return_value;
// --width;
// }
// else *--s = '-';
*--s = '-';
}
// volatile int count;
int count;
count = s - print_buf;
int xx;
for (xx = 0; xx < count; xx++) { // the string is formed in the end of buffer
print_buf[xx] = *s; // this code move to the beginning
s++;
}
return return_value;
}
#endif
#endif
/******************************************************************************
* Embedded version of the "printf()" function - use the same parameters
* "u" (unsigned long), "d" (signed long), "x/X" (hexadecimal)
* "b" (binary), "f" (float), "e" (float in scientific notation)
* Limitations: integer numbers need be casted with (long) and float/double with (float - standard)
* or (double - precision_float)
* integer numbers limited by 32bits signed size (long)
* float variables limited to 4 decimal places in standard (reduce size and performance)
* float variables limited to 9 decimal places in precision (reduce size and performance)
* Input: char *format (like standard "printf( )")
* return: int return_value (number of characters printed - like standard printf)
******************************************************************************/
unsigned int embedded_printf(char *format, ...)
{
char print_buf[PRINT_BUF_LEN];
unsigned int width, pad;
unsigned int return_value = 0;
unsigned int dp = 0;
va_list args;
va_start(args, format);
for (; *format != 0; ++format) {
if (*format == '%') {
++format;
width = pad = 0;
if (*format == '\0') break;
if (*format == '%') goto out;
if (*format == '-') {
++format;
#ifdef ENABLE_PAD_
pad = PAD_RIGHT;
#endif
}
while (*format == '0') {
++format;
#ifdef ENABLE_PAD_
pad |= PAD_ZERO;
#endif
}
for (; *format >= '0' && *format <= '9'; ++format) {
// width *= 10;
width = (width << 3) + (width << 1); // x * 10 = x * 8 + x * 2
width += *format - '0';
}
if (*format == '.') {
++format;
for (; *format >= '0' && *format <= '9'; ++format) {
// dp *= 10;
dp = (dp << 3) + (dp << 1); // x * 10 = x * 8 + x * 2
dp += *format - '0';
}
}
if (*format == 's') { // if string - call the respective function
char *s = (char *)va_arg(args, int);
return_value += embedded_prints(s ? s : "(null)", width, pad);
continue;
}
if (*format == 'd') { // if signed long - call the respective function
return_value += embedded_ltoa(print_buf, va_arg(args, int32_t), DECIMAL, SIGNED, width, pad, LOWER_CASE);
return_value += embedded_prints(print_buf, width, pad);
continue;
}
if (*format == 'x') { // if hexadecimal (lowercase) - call the respective function
return_value += embedded_ltoa(print_buf, va_arg(args, int32_t), HEXADEC, NON_SIGNED, width, pad, LOWER_CASE);
return_value += embedded_prints(print_buf, width, pad);
continue;
}
if (*format == 'X') { // if hexadecimal (uppercase) - call the respective function
return_value += embedded_ltoa(print_buf, va_arg(args, int32_t), HEXADEC, NON_SIGNED, width, pad, UPPER_CASE);
return_value += embedded_prints(print_buf, width, pad);
continue;
}
if (*format == 'u') { // if unsigned long - call the respective function
return_value += embedded_ltoa(print_buf, va_arg(args, int32_t), DECIMAL, NON_SIGNED, width, pad, LOWER_CASE);
return_value += embedded_prints(print_buf, width, pad);
continue;
}
if (*format == 'c') { // if a char - direct put in the serial
char scr[2];
scr[0] = (char)va_arg(args, int);
scr[1] = '\0';
return_value += embedded_prints(scr, width, pad);
continue;
}
#ifdef ENABLE_FLOAT_
if (*format == 'f') { // if float/double - call the respective function
#ifdef PRECISION_FLOAT_
return_value += embedded_ftoa(print_buf, va_arg(args, double), dp, NON_SCI);
#else
return_value += embedded_ftoa(print_buf, (float)va_arg(args, double), dp, NON_SCI);
#endif
return_value += embedded_prints(print_buf, 0, 0);
continue;
}
if (*format == 'e') { // if scientific notation - call the respective function
#ifdef PRECISION_FLOAT_
return_value += embedded_ftoa(print_buf, va_arg(args, double), dp, SCI);
#else
return_value += embedded_ftoa(print_buf, (float)va_arg(args, double), dp, SCI);
#endif
return_value += embedded_prints(print_buf, 0, 0);
continue;
}
#endif
#ifdef ENABLE_BINARY_
if (*format == 'b') { // if binary - call the respective function
return_value += embedded_ltoa(print_buf, va_arg(args, int32_t), BINARY, NON_SIGNED, width, pad, LOWER_CASE);
return_value += embedded_prints(print_buf, width, 0);
continue;
}
#endif
}
else {
out:
putChar(*format);
++return_value;
}
}
va_end(args);
return return_value;
}
//void set_label(unsigned int x)
//{
// label = x;
//}
/******************************************************************************
* simple function to print a String
******************************************************************************/
unsigned int print_string(char *string)
{
return embedded_prints(string, 0, NON_PAD);
}
/******************************************************************************
* simple function to print a signed long
******************************************************************************/
unsigned int print_long(long number)
{
char buffer[PRINT_BUF_LEN];
embedded_ltoa(buffer, number, DECIMAL, SIGNED, 0, NON_PAD, LOWER_CASE);
return embedded_prints(buffer, 0, NON_PAD);
}
/******************************************************************************
* simple function to print a unsigned long
******************************************************************************/
unsigned int print_ulong(unsigned long number)
{
char buffer[PRINT_BUF_LEN];
embedded_ltoa(buffer, number, DECIMAL, NON_SIGNED, 0, NON_PAD, LOWER_CASE);
return embedded_prints(buffer, 0, NON_PAD);
}
/******************************************************************************
* simple function to print a hexadecimal
******************************************************************************/
unsigned int print_hexa(long number)
{
char buffer[PRINT_BUF_LEN];
embedded_ltoa(buffer, number, HEXADEC, NON_SIGNED, 0, NON_PAD, LOWER_CASE);
return embedded_prints(buffer, 0, NON_PAD);
}
#ifdef ENABLE_BINARY_
/******************************************************************************
* simple function to print a binary
******************************************************************************/
unsigned int print_binary(long number, unsigned int bits)
{
char buffer[PRINT_BUF_LEN];
embedded_ltoa(buffer, number, BINARY, NON_SIGNED, bits, NON_PAD, LOWER_CASE);
return embedded_prints(buffer, 0, NON_PAD);
}
#endif
#ifdef ENABLE_FLOAT_
/******************************************************************************
* simple function to print a float/double
******************************************************************************/
#ifdef PRECISION_FLOAT_
unsigned int print_float(double number, int dp)
{
char buffer[PRINT_BUF_LEN];
embedded_ftoa(buffer, number, dp, NON_SCI);
return embedded_prints(buffer, 0, NON_PAD);
}
#else
unsigned int print_float(float number, int dp)
{
char buffer[PRINT_BUF_LEN];
embedded_ftoa(buffer, number, dp, NON_SCI);
return embedded_prints(buffer, 0, NON_PAD);
}
#endif
/******************************************************************************
* simple function to print in scientific notation - cast to (double)
******************************************************************************/
#ifdef PRECISION_FLOAT_
unsigned int print_scientific(double number, int dp)
{
char buffer[PRINT_BUF_LEN];
embedded_ftoa(buffer, number, dp, SCI);
return embedded_prints(buffer, 0, NON_PAD);
}
#else
unsigned int print_scientific(float number, int dp)
{
char buffer[PRINT_BUF_LEN];
embedded_ftoa(buffer, number, dp, SCI);
return embedded_prints(buffer, 0, NON_PAD);
}
#endif
#endif
#ifdef PRECISION_FLOAT_
//void embedded_string2number(char *string, double *number)
void embedded_string2number(unsigned char *string, double *number)
{
unsigned int neg = 0; // indicate a negative number
uint32_t integer = 0; // save the integer part
uint32_t decimal = 0; // save the decimal part
volatile uint32_t decimal_count = 1; // count the number of digits
double number_float = 0; // used to calculate the number
if (*string == '-') // check if negative
{
++neg;
// *string++;
string++;
}
while ((*string != '.') && (*string))// convert the integer part before the '.'
{
// if (*string >= '0' && *string <= '9')
// {
integer *= 10;
integer += *string - '0';
// }
// *string++;
string++;
}
if (*string == '.') // verify the '.'
{
// *string++;
string++;
decimal_count = 1;
while (*string) // convert decimal part
{
decimal *= 10;
decimal += *string - '0';
decimal_count *= 10;
// *string++;
string++;
}
}
number_float = (double) integer + (double) decimal / (double) decimal_count;
if (neg) {
number_float = number_float * (-1);
}
*number = number_float;
}
#else
//void embedded_string2number(char *string, float *number)
void embedded_string2number(unsigned char *string, float *number)
{
unsigned int neg = 0; // indicate a negative number
uint32_t integer = 0; // save the integer part
uint32_t decimal = 0; // save the decimal part
volatile uint32_t decimal_count = 1; // count the number of digits
float number_float = 0; // used to calculate the number
if (*string == '-') // check if negative
{
++neg;
// *string++;
string++;
}
while ((*string != '.') && (*string))// convert the integer part before the '.'
{
// if (*string >= '0' && *string <= '9')
// {
integer *= 10;
integer += *string - '0';
// }
// *string++;
string++;
}
if (*string == '.') // verify the '.'
{
// *string++;
string++;
decimal_count = 1;
while (*string) // convert decimal part
{
decimal *= 10;
decimal += *string - '0';
decimal_count *= 10;
// *string++;
string++;
}
}
number_float = (float) integer + (float) decimal / (float) decimal_count;
if (neg)
{
number_float = number_float * (-1);
}
*number = number_float;
}
#endif