ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
n2a.c
Go to the documentation of this file.
1 
28 #ifdef PRINTF_TEST
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdint.h>
33 #include <stdarg.h>
34 #include <string.h>
35 #include <math.h>
36 
37 #include "mathio.h"
38 
39 
40 void test10(long long max)
41 {
42  long long val;
43  long long s;
44  printf("testing mul10str() function: (%lld) values\n", max);
45  for(val=0;val<max;++val)
46  {
47  s = val;
48  mul10str((uint8_t *) &s, sizeof(s));
49  if(s != (val * 10))
50  printf("%lld * 10 = %lld, != %lld\n", val, (val * 10), s);
51  }
52  printf("Done %lld tests\n\n", val);
53 }
54 
55 
56 
57 int main(int argc, char *argv[])
58 {
59 
60  int len;
61  int size;
62  int sign_ch;
63  char line[1024];
64  char numresult[1024];
65  long long val;
66  __int128_t val2;
67 
68 
69  printf("sizeof(long) = %d\n", (int) sizeof(long));
70  printf("sizeof(long long) = %d\n", (int) sizeof(long long));
71  printf("sizeof(val) = %d\n", (int) sizeof(val));
72  printf("sizeof(__uint128_t) = %d\n", (int) sizeof(__uint128_t));
73  printf("sizeof( intmax_t ) == %d\n", (int) sizeof( intmax_t ));
74 
75  test10(1000000LL);
76 
77  while(1) {
78  printf("Enter a number or ENTER to quit:");
79  fgets(line, 1020,stdin);
80  len = strlen(line);
81  while(len)
82  {
83  --len;
84  if(line[len] < ' ')
85  line[len] = 0;
86  }
87  if(!*line)
88  break;
89  sign_ch = 0;
90  val2 = strto128(line, NULL, 10);
91  if(val2 < (__int128_t) 0)
92  {
93  sign_ch = '-';
94  val2 = -val2;
95  }
96  size = bin2num(numresult, 1022, 1, 10, (uint8_t *) &val2, sizeof(val2), sign_ch);
97  //dump(numresult,size);
98  printf("numresult[%s]\n",numresult);
99  }
100 }
101 #endif
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
Definition: stringsup.c:146
MEMSPACE int mul10str(uint8_t *str, int size)
Fast multiply number of any size by 10.
Definition: mathio.c:108
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
Definition: posix.c:420
MEMSPACE int bin2num(uint8_t *str, int strmax, int nummin, int base, uint8_t *nump, int numsize, int sign_ch)
Convert an unsigned number (numsize bytes in size) to ASCII in specified base Notes: No limit except ...
Definition: printf.c:139
#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.
#define stdin
define stdin, stdout and stderr
Definition: posix.h:269
MEMSPACE int printf(const char *format,...)
unsigned char uint8_t
Definition: send.c:17