ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
test_printf.c
Go to the documentation of this file.
1 
27 // only used when testing standalone on linux
28 #ifdef PRINTF_TEST
29 
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <ctype.h>
34 
35 #include <stdarg.h>
36 #include <stdint.h>
37 #include <math.h>
38 
39 #include "mathio.h"
40 
41 
59 long long numcmp(uint8_t *str1, uint8_t *str2, int max)
60 {
61 
62  int nzflag = 0;
63  uint8_t n1[64+2],n2[64+2];
64  uint8_t c1,c2;
65  int ind1,ind2;
66  int len1,len2;
67  int count = 0;
68  int offset = 0;
69  long long diff, l1,l2;
70 
71  uint8_t *save1 = str1;
72  uint8_t *save2 = str2;
73 
74  ind1 = 0;
75  ind2 = 0;
76 
77  if(max > 64)
78  max = 64;
79 
80  len1 = strlen(save1);
81  len2 = strlen(save2);
82  if(len1 != len2)
83  {
84  printf("WARN: length mismatch (%d) != (%d)\n",
85  len1,len2);
86  printf(" str1:[%s]\n", save1);
87  printf(" str2:[%s]\n", save2);
88  return(-1LL);
89  }
90 
91  // discard leading space,,+/- characters
92  while( (c1 = *str1) && (c2 = *str2) )
93  {
94  if( isdigit(c1) || isdigit(c2) )
95  break;
96 
97  if(c1 != c2)
98  {
99  n1[ind1] = 0;
100  n2[ind2] = 0;
101  printf("WARN: mismatch at (%d)\n", count);
102  printf(" str1 offset:%d\n", (int)(str1 - save1));
103  printf(" str2 offset:%d\n", (int)(str2 - save2));
104  printf(" str1:[%s]\n", save1);
105  printf(" str2:[%s]\n", save2);
106  printf(" n1:[%s]\n", n1);
107  printf(" n2:[%s]\n", n2);
108  return(-1LL);
109  }
110 
111  // sign an leading zeros
112  if(c1 == '.' || c1 == ' ' || c1 == '-' || c1 == '+')
113  {
114  ++str1;
115  ++str2;
116  ++count;
117  continue;
118  }
119  break;
120  }
121 
122  while( (c1 = *str1) && (c2 = *str2) )
123  {
124  if( c1 == '.' && c2 == '.' )
125  {
126  ++str1;
127  ++str2;
128  ++count;
129  continue;
130  }
131 
132  if( !isdigit(c1) || !isdigit(c2) )
133  break;
134 
135  if(!nzflag && (c1 != '0' || c2 != '0'))
136  nzflag = 1;
137 
138  if(nzflag)
139  {
140  // no more then 16 digits
141  if(ind1 < max)
142  {
143  n1[ind1++] = c1;
144  n2[ind2++] = c2;
145  }
146  }
147  ++count;
148  ++str1;
149  ++str2;
150  }
151  n1[ind1] = 0;
152  n2[ind2] = 0;
153 
154  c1 = *str1;
155  c2 = *str2;
156 
157  if(c1 != c2)
158  {
159  printf("WARN: mismatch at (%d) %02X != %02X\n",
160  (int) count, (int) c1, (int) c2);
161  printf(" str1 offset:%d\n", (int)(str1 - save1));
162  printf(" str2 offset:%d\n", (int)(str2 - save2));
163  printf(" str1:[%s]\n", save1);
164  printf(" str2:[%s]\n", save2);
165  printf(" n1:[%s]\n", n1);
166  printf(" n2:[%s]\n", n2);
167  return(-1LL);
168  }
169  if(c1 == 'e' || c1 == 'E')
170  {
171  if(strcmp(str1,str2) != 0)
172  {
173  printf("WARN: exponent mismatch at offset:(%d)\n", count);
174  printf(" str1:[%s]\n", save1);
175  printf(" str2:[%s]\n", save2);
176  printf(" n1:[%s]\n", n1);
177  printf(" n2:[%s]\n", n2);
178  return(-1LL);
179  }
180  }
181 
182  l1 = strtoll(n1,NULL,10);
183  l2 = strtoll(n2,NULL,10);
184  diff = l1 - l2;
185  if(diff < 0)
186  diff = -diff;
187 
188  return(diff);
189 }
190 
191 
192 // =============================================
197 static void _putc_fn(struct _printf_t *p, char ch)
198 {
199  p->sent++;
200  putchar(ch);
201 }
202 
207 int t_printf(const char *format, ...)
208 {
209  int len;
210  int i;
211  printf_t fn;
212  va_list va;
213 
214  fn.put = _putc_fn;
215  fn.sent = 0;
216 
217  va_start(va, format);
218  _printf_fn(&fn, format, va);
219  va_end(va);
220 
221  len = fn.sent;
222  return (len);
223 }
224 
225 
226 // =============================================
233 MEMSPACE
234 int t_vsnprintf(char* str, size_t size, const char *format, va_list va)
235 {
236 
237  int len;
238  char *save = str;
239  printf_t fn;
240 
241  *str = 0;
242 
243  fn.put = _putc_buffer_fn;
244  fn.len = size;
245  fn.sent = 0;
246  fn.buffer = (void *) str;
247 
248  _printf_fn(&fn, format, va);
249 
250  // FIXME check size should == fn.size on exit
251  len = strlen(save);
252  return( len );
253 }
254 
255 
256 // =============================================
257 int display_good = 0;
258 long tp_good = 0; //@brief total good tests
259 long tp_bad = 0; //@brief total bad tests
260 long tp_fmt = 0; //@brief total empty format string errors
261 
267 MEMSPACE
268 void tp(const char *format, ...)
269 {
270  char str0[1024];
271  char fmt[1024];
272  char str1[1024];
273  char str2[1024];
274  int f;
275  int find, ind, len;
276  int matched;
277  long long error;
278  va_list va;
279  int digits;
280 
281  memset(str0,sizeof(str0)-1,0);
282  memset(str1,sizeof(str1)-1,0);
283  memset(str2,sizeof(str2)-1,0);
284  memset(fmt,sizeof(fmt)-1,0);
285 
286  // We want to save only type and type size specifiers)
287  find = 0;
288  fmt[find++] = '%';
289 
290  len = strlen(format);
291  if(len > 0)
292  {
293  ind = len - 1;
294  }
295  else
296  {
297  printf("ERROR: empty format\n");
298  printf(" G[%s]\n", str1);
299  printf(" B[%s]\n", str2);
300  printf("\n");
301  ++tp_fmt;
302  return;
303  }
304 
305  // We may have a size adjustment specifier
306  //FIXME add more as printf gains more type size conversion specifiers
307  if(ind >= 2)
308  {
309  f = format[ind-2];
310  if(f == 'l')
311  fmt[find++] = f;
312  }
313  f = format[ind-1];
314  if(f == 'l' || f == 'h')
315  fmt[find++] = f;
316 
317  // This should be the primary conversion type specifier
318  if(ind)
319  {
320  f = format[ind];
321  fmt[find++] = f;
322  }
323  fmt[find++] = 0;
324 
325  // GLIBC printf in str0 without extra specifiers
326  va_start(va, format);
327  len = vsnprintf(str0, sizeof(str0)-1, fmt, va);
328  va_end(va);
329  fflush(stdout);
330 
331  // GLIBC printf in str1
332  va_start(va, format);
333  len = vsnprintf(str1, sizeof(str1)-1, format, va);
334  va_end(va);
335  fflush(stdout);
336 
337  // Our Printf in str2
338  va_start(va, format);
339  len = t_vsnprintf(str2, sizeof(str2)-1, format, va);
340  va_end(va);
341  fflush(stdout);
342 
343 
344 
345  //FIXME add more as printf gains more conversion functions
346  if(f == 'g' || f == 'G' || f == 'e' || f == 'E' || f == 'f' || f == 'F')
347  {
348  /*
349  * Single mantissa 24bits base10 digits 7.22
350  * exponent 8bits base10 exponent 37
351  * Double mantissa 53bits base10 digits 15.95
352  * exponent 11bits base10 exponent 307
353  */
354  if(sizeof(double) == 8)
355  digits = 16;
356  else if(sizeof(double) == 4)
357  digits = 7;
358  else
359  {
360  fprintf(stderr,"Unexpected size of double:%d\n", (int)sizeof(double));
361  exit(1);
362  }
363 
364  // Compare results to N digit window
365  error = numcmp(str1,str2,digits);
366 
367  // A double 1 LSB error would be 10LL
368  // Remember the numbers may be rounded so we use less then 15LL
369  if(error < 0 || error > 14LL)
370  {
371  printf("ERROR: [%s], [%s]\n", format, str0);
372  printf(" G[%s]\n", str1);
373  printf(" B[%s]\n", str2);
374  printf(" error:%lld\n", error);
375  ++tp_bad;
376  }
377  else
378  {
379  ++tp_good;
380  if(display_good)
381  {
382  printf("OK: [%s], [%s]\n", format, str0);
383  printf(" G[%s]\n", str1);
384  }
385  }
386  }
387  else
388  {
389  if(strcmp(str1,str2) != 0)
390  {
391  printf("ERROR: [%s], [%s]\n", format, str0);
392  printf(" G[%s]\n", str1);
393  printf(" B[%s]\n", str2);
394  ++tp_bad;
395  }
396  else
397  {
398  ++tp_good;
399  if(display_good)
400  {
401  printf("OK: [%s], [%s]\n", format, str0);
402  printf(" G[%s]\n", str1);
403  }
404  }
405  }
406  fflush(stdout);
407  return;
408  fflush(stdout);
409 }
410 
411 
412 
413 // =============================================
419 MEMSPACE
420 void random_tests(int flag, char *size)
421 {
422  int snum;
423  int inum;
424  long lnum;
425  long long llnum;
426  double dnum, scale;
427 
428  int width,prec;
429  int exp10;
430  int shift;
431  int precf;
432  double sign;
433  int digits;
434  int dotf;
435  int signind;
436  char *signop = "+- 0";
437  char format[1024];
438  char tmp[1024];
439 
440  memset(format,0,128);
441 
442 
443  if(drand48() >= .5)
444  sign = 1.0;
445  else
446  sign = -1.0;
447 
448  if(drand48() >= .5)
449  precf = 1;
450  else
451  precf = 0;
452  if(drand48() >= .5)
453  dotf = 1;
454  else
455  dotf = 0;
456  signind = drand48() * 3.99999;
457 
458  //printf("num:%ld\n",num);
459 
460  // With f we limit the exponent to +/-2 ** sizeof(long long)
461  if(flag == 'e' || flag == 'f' )
462  {
463  /*
464  * Single mantissa 24bits base10 digits 7.22
465  * exponent 8bits base10 exponent 37
466  * Double mantissa 53bits base10 digits 15.95
467  * exponent 11bits base10 exponent 307
468  */
469 
470  // We only test exponent to +/- digits * 2
471  // If we test numbers greater then (10 ** digits) we start getting
472  // roundoff/truncation errors
473  //
474  // Glibc printf uses extended precision functions (ie. > double size)
475 
476  if(sizeof(double) == 8)
477  {
478  digits = 16;
479  }
480  else if(sizeof(double) == 4)
481  {
482  digits = 7;
483  }
484  else
485  {
486  fprintf(stderr,"Unexpected size of double:%d\n",(int)sizeof(double));
487  exit(1);
488  }
489  width = drand48() * 2.0 * digits;
490  prec = drand48() * 2.0 * digits;
491  if(precf || dotf)
492  snprintf(format,sizeof(format)-1, "%%%c%d.%d%c", signop[signind], width, prec, flag);
493  else
494  snprintf(format,sizeof(format)-1, "%%%c%d%c", signop[signind], width, flag);
495 
496 
497  exp10 = ((drand48() * 2.0) - 1.0) * (double) (digits * 2);
498  scale = iexp(10.0, exp10);
499  dnum = ( sign * drand48() * scale);
500  tp(format, dnum);
501  }
502  else /* ASSUME integer or long arguments */
503  {
504  if(strcmp(size,"short") == 0)
505  {
506  width = drand48() * (double)(sizeof(short) * 8)/3.321928095;
507  prec = drand48() * (double)(sizeof(short) * 8)/3.321928095;
508  shift = drand48() * (double) sizeof(int) * 8;
509  scale = pow(2.0, shift);
510  inum = (int) ( sign * drand48() * scale);
511  if(precf || dotf)
512  snprintf(format,sizeof(format)-1, "%%%c%d.%dh%c", signop[signind], width, prec, flag);
513  else
514  snprintf(format,sizeof(format)-1, "%%%c%dh%c", signop[signind], width, flag);
515  tp(format, inum);
516  }
517  else if(strcmp(size,"int") == 0)
518  {
519  width = drand48() * (double)(sizeof(int) * 8)/3.321928095;
520  prec = drand48() * (double)(sizeof(int) * 8)/3.321928095;
521  shift = drand48() * (double) sizeof(int) * 8;
522  scale = pow(2.0, shift);
523  inum = (int) ( sign * drand48() * scale);
524  if(precf || dotf)
525  snprintf(format,sizeof(format)-1, "%%%c%d.%d%c", signop[signind], width, prec, flag);
526  else
527  snprintf(format,sizeof(format)-1, "%%%c%d%c", signop[signind], width, flag);
528  tp(format, inum);
529  }
530  else if(strcmp(size,"long") == 0)
531  {
532  width = drand48() * (double)(sizeof(long) * 8)/3.321928095;
533  prec = drand48() * (double)(sizeof(long) * 8)/3.321928095;
534  shift = drand48() * (double) sizeof(long) * 8;
535  scale = pow(2.0, shift);
536  lnum = (long) ( sign * drand48() * scale);
537  if(precf || dotf)
538  snprintf(format,sizeof(format)-1, "%%%c%d.%dl%c", signop[signind], width, prec, flag);
539  else
540  snprintf(format,sizeof(format)-1, "%%%c%dl%c", signop[signind], width, flag);
541  tp(format, lnum);
542  }
543  else if(strcmp(size,"long long") == 0)
544  {
545  width = drand48() * (double)(sizeof(long long) * 8)/3.321928095;
546  prec = drand48() * (double)(sizeof(long long) * 8)/3.321928095;
547  shift = drand48() * (double) sizeof(long long) * 8;
548  scale = pow(2.0, shift);
549  llnum = (long) ( sign * drand48() * scale);
550  if(precf || dotf)
551  snprintf(format,sizeof(format)-1, "%%%c%d.%dll%c", signop[signind], width, prec, flag);
552  else
553  snprintf(format,sizeof(format)-1, "%%%c%dll%c", signop[signind], width, flag);
554  tp(format, llnum);
555  }
556  else
557  {
558  fprintf(stderr,"random_tests: bad size[%s]\n", size);
559  exit(1);
560  }
561  }
562 }
563 
564 // =============================================
568 void tests()
569 {
570  int i1 = -1;
571  int l1 = -1L;
572 
573  printf("=======================\n");
574  printf("Start of Manual tests\n");
575  tp("%-0d", 0);
576  tp("%-0u", 0);
577  tp("%-0u", 1);
578  tp("%-0u", -1);
579  tp("%00u", 0);
580  tp("%00u", 1);
581  tp("%00u", -1);
582  tp("% -.5u", 123);
583  tp("% - .5u", -123);
584  tp("% 1.5u", -6);
585  tp("%+1.4u", 372);
586  tp("%-0lu", 0);
587  tp("%-0lu", 1);
588  tp("%-0lu", -1);
589  tp("%00lu", 0);
590  tp("%00lu", 1);
591  tp("%00lu", -1);
592  tp("% -.5lu", 123);
593  tp("% - .5lu", -123);
594  tp("% 1.5lu", -6);
595  tp("%+1.4lu", 372);
596  tp("%-0ld", 0);
597  tp("%-0ld", 1);
598  tp("%-0ld", -1);
599  tp("%00ld", 0);
600  tp("%00ld", 1);
601  tp("%00ld", -1);
602  tp("% -.5ld", 123);
603  tp("% - .5ld", -123);
604  tp("% 1.5ld", -6);
605  if(display_good)
606  printf("\n");
607 
608  tp("%-0d", 0);
609  tp("%-0d", 1);
610  tp("%-0d", -1);
611  tp("%00d", 0);
612  tp("%00d", 1);
613  tp("%00d", -1);
614  tp("% -.5d", 123);
615  tp("% - .5d", -123);
616  tp("% 1.5d", -6);
617  tp("%+1.4d", 372);
618  tp("%+03d", 0);
619  tp("%+03d", -1);
620  tp("%+03d", 1);
621  tp("%+03.0d", 0);
622  tp("%+03.0d", -1);
623  tp("%+03.0d", 1);
624  tp("%-+03d", 0);
625  tp("%-+03d", -1);
626  tp("%-+03d", 1);
627  tp("%-+03.0d", 0);
628  tp("%-+03.0d", -1);
629  tp("%-+03.0d", 1);
630  if(display_good)
631  printf("\n");
632 
633  tp("%+0f", -0.196764);
634  tp("%08.0f", 1.5);
635  tp("%08.0f", -1.5);
636  tp("%08.4f", 0.0);
637  tp("%30.2f", 0.123456789012345678901234567890);
638  tp("%30.2f", 0.00000000000123456789012345678901234567890);
639  tp("%+30.15f", 0.00000000000123456789012345678901234567890);
640  tp("%+030.15f", 0.00000000000123456789012345678901234567890);
641  tp("% 30.15f", 0.00000000000123456789012345678901234567890);
642  tp("%+30.15f", 123456.789012345678901234567890);
643  tp("%+030.15f", 123456.789012345678901234567890);
644  tp("%+30.15f", -123456.789012345678901234567890);
645  tp("%+030.15f", -123456.789012345678901234567890);
646  tp("%+15.13f", -0.0085833);
647  tp("%+15.13f", 0.0085833);
648  tp("%+15.13f", 0.085833);
649  tp("%+15.13f", 0.85833);
650  tp("%+15.13f", 8.5833);
651  tp("%+15.13f", 85.833);
652  tp("%+15.13f", 123456789012345678901234567890.159265358979);
653  tp("%+15.2f", 123456789012345678901234567890.159265358979);
654  tp("%15.2f", 123456789012345678901234567890.159265358979);
655  tp("%f", 123456789012345678901234567890.159265358979);
656  tp("%08.0f", 1.0);
657  tp("%08.0f", -1.0);
658  tp("%f", 0.0);
659  tp("%8.2f", 0.0);
660  tp("%08.4f", 12.89);
661  tp("%08.4f", -12.89);
662  tp("%.2f", 1234567.89);
663  tp("%.2f", -1234567.89);
664  tp("%+.2f", 1234567.89);
665  tp("%+.2f", -1234567.89);
666  tp("% .2f", 1234567.89);
667  tp("%08.4f", 0.0);
668  tp("%+014.8f", 3.14159265358979);
669  tp("%+14.8f", 3.141);
670  tp("% .2f", -1234567.89);
671  if(display_good)
672  printf("\n");
673 
674  tp("%015e", -314.159265358979);
675  tp("%020.5e", 314.159265358979);
676  tp("%020.5e", -314.159265358979);
677  tp("%-+015.4e", 314.159265358979);
678  tp("%-+015.4e", -314.159265358979);
679  tp("%-+025.10e", 314.159265358979);
680  tp("%-+025.10e", -314.159265358979);
681  tp("%-+25.10e", 314.159265358979);
682  tp("%-+25.10e", -314.159265358979);
683  tp("%+25.10e", 314.159265358979);
684  tp("%+25.10e", -314.159265358979);
685  tp("% 015.4e", 314.159265358979);
686  tp("% 015.4e", -314.159265358979);
687  tp("%015e", -314.159265358979);
688  tp("%020.5e", 314.159265358979e-17);
689  tp("%020.5e", -314.159265358979e-17);
690  tp("%-+015.4e", 314.159265358979e-17);
691  tp("%-+015.4e", -314.159265358979e-17);
692  tp("%-+025.10e", 314.159265358979e-17);
693  tp("%-+025.10e", -314.159265358979e-17);
694  tp("%-+25.10e", 314.159265358979e-17);
695  tp("%-+25.10e", -314.159265358979e-17);
696  tp("%+25.10e", 314.159265358979e-17);
697  tp("%+25.10e", -314.159265358979e-17);
698  tp("% 015.4e", 314.159265358979e-17);
699  tp("%010.5e", 314.159265358979e-17);
700  tp("%010.5e", -314.159265358979e-17);
701  tp("%010.5e", 123456789012345678901234567890.159265358979);
702  if(display_good)
703  printf("\n");
704 
705  tp("%e", 314.159265358979);
706  tp("%e", -314.159265358979);
707  tp("%+e", -314.159265358979);
708  tp("% e", 314.159265358979);
709  tp("%-+e", 314.159265358979);
710  tp("%-+e", -314.159265358979);
711  tp("%-+15.4e", 314.159265358979);
712  tp("%-+15.4e", -314.159265358979);
713  tp("%-+15e", 314.159265358979);
714  tp("%-+15e", -314.159265358979);
715  tp("%15e", 314.159265358979);
716  tp("%15e", -314.159265358979);
717  tp("%20.5e", 314.159265358979);
718  tp("%20.5e", -314.159265358979);
719  tp("%08.4e", 314.159265358979);
720  tp("%08.4e", -314.159265358979);
721  tp("%-+08.4e", 314.159265358979);
722  tp("%-+08.4e", -314.159265358979);
723  tp("% 08.4e", 314.159265358979);
724  tp("% 08.4e", -314.159265358979);
725  tp("%10.5e", 314.159265358979);
726  tp("%10.5e", -314.159265358979);
727  tp("%10.5e", 123456789012345678901234567890.159265358979);
728  tp("%10.10e", 123456789012345678901234567890.159265358979);
729  tp("%10.15e", 123456789012345678901234567890.159265358979);
730  tp("%10.20e", 123456789012345678901234567890.159265358979);
731  tp("%10.20e", 123456789012345678901234567890.159265358979e-50);
732  tp("%10.20e", 123456789012345678901234567890.159265358979e+50);
733  tp("%10.20e", 123456789012345678901234567890.159265358979e-100);
734  tp("%10.20e", 123456789012345678901234567890.159265358979e+100);
735  if(display_good)
736  printf("\n");
737 
738 
739  tp("%c", 'a');
740  tp("%-5c", 'a');
741  tp("%5c", 'a');
742  if(display_good)
743  printf("\n");
744  tp("-20.2s", "abc");
745  tp("10.5s", "abc");
746  if(display_good)
747  printf("\n");
748  printf("End of Manual tests\n");
749  printf("=======================\n");
750  printf("\n");
751 }
752 
756 #define MAXSTR 256
757 int main(int argc, char *argv[])
758 {
759 
760  uint8_t str[MAXSTR+1];
761  long lnum, mask;
762  int i;
763  int k;
764  int size;
765 #ifdef __SIZEOF_INT128__
766  __uint128_t num128;
767 #endif
768 
769  f_t f;
770 
771  char *intops = "duxXo";
772  char *sizeops[] = { "short", "int", "long", "long long", NULL };
773  char *floatops = "fe";
774 
775  printf("=======================\n");
776  printf("Start of Manual tests\n");
777 
778 // Test basic type sizes
779  t_printf("sizeof (double) = %d\n", sizeof (double ) );
780  t_printf("sizeof (float) = %d\n", sizeof (float ) );
781 #ifdef __SIZEOF_INT128__
782  t_printf("sizeof (__uint128_t) = %d\n", sizeof (__uint128_t) );
783 #endif
784  t_printf("sizeof (long long) = %d\n", sizeof (long long ) );
785  t_printf("sizeof (long) = %d\n", sizeof (long ) );
786  t_printf("sizeof (short) = %d\n", sizeof (short) );
787  t_printf("sizeof (int) = %d\n", sizeof (int ) );
788  t_printf("sizeof (char) = %d\n", sizeof (char ) );
789  printf("=======================\n");
790  printf("\n");
791 
792 
793 #ifdef __SIZEOF_INT128__
794  printf("=======================\n");
795  printf("Start of 128 bit int tests\n");
796  // There are no 128bit int constants in gcc - sigh
797  num128 = 1;
798  for(i=0;i<128;++i)
799  {
800  t_printf("2**%03d = [%I128d]\n", i, num128);
801  fflush(stdout);
802  num128 <<= 1;
803  }
804  printf("=======================\n");
805  printf("\n");
806  printf("=======================\n");
807  printf("Start of 128 bit int tests - 40 field width\n");
808  num128 = 1;
809  for(i=0;i<128;++i)
810  {
811  t_printf("2**%03d = [%40I128d]\n", i, num128);
812  fflush(stdout);
813  num128 <<= 1;
814  }
815  printf("=======================\n");
816  printf("\n");
817  printf("=======================\n");
818  printf("Start of 128 bit int tests - 40 field width and leading 0's\n");
819  num128 = 1;
820  for(i=0;i<128;++i)
821  {
822  t_printf("2**%03d = [%+040I128d]\n", i, num128);
823  fflush(stdout);
824  num128 <<= 1;
825  }
826  printf("=======================\n");
827  printf("\n");
828 #endif
829 
830  display_good = 0;
831  tests();
832 
833  printf("\n\n");
834  printf("Start of random tests\n");
835 
836 
837  display_good = 0;
838  for(size=0;sizeops[size];++size)
839  {
840  for(k=0;intops[k];++k)
841  {
842  tp_good = 0;
843  tp_bad = 0;
844  printf("=======================\n");
845  printf("Start:(%c:%s)\n", intops[k], sizeops[size]);
846  for(i=0;i<1000000;++i)
847  random_tests(intops[k], sizeops[size]);
848  printf("End: (%c:%s)\n", intops[k], sizeops[size]);
849  printf("Good:%ld, Bad:%ld, fmt:%ld\n", tp_good, tp_bad, tp_fmt);
850  printf("=======================\n");
851  }
852  }
853 
854  display_good = 0;
855  for(k=0;floatops[k];++k)
856  {
857  tp_good = 0;
858  tp_bad = 0;
859  printf("=======================\n");
860  printf("Start:(%c)\n", floatops[k]);
861  for(i=0;i<1000000;++i)
862  random_tests(floatops[k], "");
863  printf("End: (%c)\n", floatops[k]);
864  printf("Good:%ld, Bad:%ld, fmt:%ld\n", tp_good, tp_bad, tp_fmt);
865  printf("=======================\n");
866  }
867  printf("\n");
868  printf("Random done\n");
869 
870  printf("=======================\n");
871  printf("testing binary leading 1's\n");
872  lnum = 0;
873  lnum = ~lnum;
874  mask = 1;
875  while(mask)
876  {
877  lnum &= ~mask;
878  mask <<= 1;
879  tp("%016lx", lnum);
880  tp("%019ld", lnum);
881  tp("%022lo", lnum);
882 
883  }
884  printf("=================================\n");
885  printf("testing binary trailing 1's\n");
886  lnum = 0;
887  mask = 1;
888  while(mask)
889  {
890  lnum |= mask;
891  mask <<= 1;
892  tp("%016lx", lnum);
893  tp("%019ld", lnum);
894  tp("%022lo", lnum);
895  }
896 
897  printf("=================================\n");
898  printf("testing base 10 9's\n");
899  lnum = 9;
900  while(1)
901  {
902  if(lnum & (1L << ((sizeof(lnum)*8)-1)))
903  break;
904  tp("%016lx", lnum);
905  tp("%019ld", lnum);
906  tp("%022lo", lnum);
907  lnum *= 10;
908  lnum += 9;
909 
910  }
911  printf("\n");
912  printf("=================================\n");
913  return(0);
914 }
915 #endif
MEMSPACE int vsnprintf(char *str, size_t size, const char *format, va_list va)
vsnprintf function
Definition: printf.c:1135
MEMSPACE int WEAK_ATR strcmp(const char *str, const char *pat)
Compare two strings.
Definition: stringsup.c:362
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
Definition: stringsup.c:146
MEMSPACE void _printf_fn(printf_t *fn, __memx const char *fmt, va_list va)
vsnprintf function
Definition: printf.c:741
MEMSPACE int fprintf(FILE *fp, const char *format,...)
fprintf function Example user defined printf function using fputc for I/O This method allows I/O to d...
Definition: posix.c:2484
#define snprintf(s, size, format, args...)
Definition: cpu.h:81
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
Definition: posix.c:351
#define NULL
Definition: cpu.h:55
int main(int argc, char *argv[])
Definition: send.c:148
Math IO functions, and verious conversion code with floating point support.
int ind
Definition: ili9341.c:373
void * buffer
Definition: mathio.h:84
MEMSPACE double iexp(double num, int exp)
int len
Definition: mathio.h:85
MEMSPACE long long strtoll(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
Definition: mathio.c:183
#define stdout
Definition: posix.h:270
#define MEMSPACE
Definition: cpu.h:25
MEMSPACE int WEAK_ATR isdigit(int c)
test if a character is a digit
Definition: stringsup.c:48
MEMSPACE int printf(const char *format,...)
#define stderr
Definition: posix.h:271
#define L(x)
Definition: cal_dex.c:54
int sent
Definition: mathio.h:86
format specifier flags
Definition: mathio.h:90
unsigned char uint8_t
Definition: send.c:17
void(* put)(struct _printf_t *, char)
Definition: mathio.h:83
MEMSPACE void _putc_buffer_fn(struct _printf_t *p, char ch)
_putc_buffer_fn - character output to a string buffer Used by snprintf and vsnprintf You can make _pr...
Definition: printf.c:1103
undefine any potential macro version of these functions
Definition: mathio.h:81