MCPcopy Create free account
hub / github.com/eembc/coremark / number

Function number

barebones/ee_printf.c:65–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static char *number(char *str, long num, int base, int size, int precision, int type)
66{
67 char c, sign, tmp[66];
68 char *dig = digits;
69 int i;
70
71 if (type & UPPERCASE) dig = upper_digits;
72 if (type & LEFT) type &= ~ZEROPAD;
73 if (base < 2 || base > 36) return 0;
74
75 c = (type & ZEROPAD) ? '0' : ' ';
76 sign = 0;
77 if (type & SIGN)
78 {
79 if (num < 0)
80 {
81 sign = '-';
82 num = -num;
83 size--;
84 }
85 else if (type & PLUS)
86 {
87 sign = '+';
88 size--;
89 }
90 else if (type & SPACE)
91 {
92 sign = ' ';
93 size--;
94 }
95 }
96
97 if (type & HEX_PREP)
98 {
99 if (base == 16)
100 size -= 2;
101 else if (base == 8)
102 size--;
103 }
104
105 i = 0;
106
107 if (num == 0)
108 tmp[i++] = '0';
109 else
110 {
111 while (num != 0)
112 {
113 tmp[i++] = dig[((unsigned long) num) % (unsigned) base];
114 num = ((unsigned long) num) / (unsigned) base;
115 }
116 }
117
118 if (i > precision) precision = i;
119 size -= precision;
120 if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' ';
121 if (sign) *str++ = sign;
122

Callers 1

ee_vsprintfFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected