30 const char *units =
"kMGTPEZY";
33 for (i = 0; units[i]; ++i) {
36 double amount = size/(double)1024;
37 if (amount<10.0)
return GBS_global_string(
"%4.2f %c%s", amount+0.005, unit, unit_suffix);
38 if (amount<100.0)
return GBS_global_string(
"%4.1f %c%s", amount+0.05, unit, unit_suffix);
47 size_t mins = seconds/60; seconds -= mins * 60;
48 size_t hours = mins/60; mins -= hours * 60;
49 size_t days = hours/24; hours -= days * 24;
51 const int MAXPRINT = 40;
53 static char buffer[MAXPRINT+1];
55 if (days>0) printed += sprintf(buffer+printed,
"%zud", days);
56 if (printed || hours>0) printed += sprintf(buffer+printed,
"%zuh", hours);
57 if (printed || mins>0) printed += sprintf(buffer+printed,
"%zum", mins);
59 printed += sprintf(buffer+printed,
"%zus", seconds);
72 const int MAXSIZE = 50;
73 static char result[MAXSIZE];
76 int printed_e = snprintf(result, MAXSIZE,
"%e", f);
arb_assert(printed_e<MAXSIZE);
77 float back_e = strtof(result,
NULp);
78 float diff_e = fabsf(f-back_e);
80 int printed_g = snprintf(buffer, MAXSIZE,
"%g", f);
arb_assert(printed_g<MAXSIZE);
81 float back_g = strtof(buffer,
NULp);
82 float diff_g = fabsf(f-back_g);
84 if (diff_g<diff_e || (diff_g == diff_e && printed_g<printed_e)) {
85 printed_e = printed_g;
88 memcpy(result, buffer, printed_g+1);
91 int printed_f = snprintf(buffer, MAXSIZE,
"%f", f);
arb_assert(printed_f<MAXSIZE);
92 float back_f = strtof(buffer,
NULp);
93 float diff_f = fabsf(f-back_f);
95 if (diff_f<diff_e || (diff_f == diff_e && printed_f<printed_e)) {
96 memcpy(result, buffer, printed_f+1);
103 const char *
result = getenv(envvar);
104 return (result && result[0]) ? result :
NULp;
115 char *
buffer = ARB_alloc<char>(strlen(path)+1+strlen(exe_name)+1);
116 const char *
start = path;
119 while (!found && start) {
120 const char *colon = strchr(start,
':');
121 int len = colon ? (colon-
start) : (
int)strlen(start);
123 memcpy(buffer, start, len);
125 strcpy(buffer+len+1, exe_name);
128 start = colon ? colon+1 :
NULp;
132 strcpy(buffer, exe_name);
144 if (strchr(path,
' ') !=
NULp) {
161 "arb may not work as expected, because\n"
164 "contains an unwanted character ('%c').",
180 #define TEST_EXPECT_FLOAT_2_ASCII(f,a) TEST_EXPECT_EQUAL(ARB_float_2_ascii(f), a)
183 #define TEST_EXPECT_FLOAT_2_ASCII(f,a) do{ \
184 TEST_EXPECT_EQUAL(ARB_float_2_ascii(f), a); \
185 TEST_EXPECT_EQUAL(ARB_float_2_ascii(strtof(a, NULp)), a); \
190 TEST_EXPECT_FLOAT_2_ASCII(3.141592e+00,
"3.141592");
191 TEST_EXPECT_FLOAT_2_ASCII(3.141592,
"3.141592");
192 TEST_EXPECT_FLOAT_2_ASCII(3.14159,
"3.14159");
194 TEST_EXPECT_FLOAT_2_ASCII(0.1,
"0.1");
195 TEST_EXPECT_FLOAT_2_ASCII(0.01,
"0.01");
196 TEST_EXPECT_FLOAT_2_ASCII(0.001,
"0.001");
197 TEST_EXPECT_FLOAT_2_ASCII(0.0001,
"0.0001");
198 TEST_EXPECT_FLOAT_2_ASCII(0.00001,
"1e-05");
199 TEST_EXPECT_FLOAT_2_ASCII(0.000001,
"1e-06");
200 TEST_EXPECT_FLOAT_2_ASCII(0.0000001,
"1e-07");
201 TEST_EXPECT_FLOAT_2_ASCII(0.00000001,
"1e-08");
202 TEST_EXPECT_FLOAT_2_ASCII(0.000000001,
"1e-09");
203 TEST_EXPECT_FLOAT_2_ASCII(0.0000000001,
"1e-10");
204 TEST_EXPECT_FLOAT_2_ASCII(0.00000000001,
"1e-11");
206 TEST_EXPECT_FLOAT_2_ASCII(10,
"10");
207 TEST_EXPECT_FLOAT_2_ASCII(100,
"100");
208 TEST_EXPECT_FLOAT_2_ASCII(1000,
"1000");
209 TEST_EXPECT_FLOAT_2_ASCII(10000,
"10000");
210 TEST_EXPECT_FLOAT_2_ASCII(100000,
"100000");
211 TEST_EXPECT_FLOAT_2_ASCII(1000000,
"1e+06");
212 TEST_EXPECT_FLOAT_2_ASCII(10000000,
"1e+07");
213 TEST_EXPECT_FLOAT_2_ASCII(100000000,
"1e+08");
214 TEST_EXPECT_FLOAT_2_ASCII(1000000000,
"1e+09");
216 TEST_EXPECT_FLOAT_2_ASCII(3141592,
"3.141592e+06");
217 TEST_EXPECT_FLOAT_2_ASCII(314159.2,
"3.141592e+05");
218 TEST_EXPECT_FLOAT_2_ASCII(31415.92,
"3.141592e+04");
219 TEST_EXPECT_FLOAT_2_ASCII(3141.592,
"3141.592041");
220 TEST_EXPECT_FLOAT_2_ASCII(3141.592041,
"3141.592041");
221 TEST_EXPECT_FLOAT_2_ASCII(314.1592,
"314.159210");
222 TEST_EXPECT_FLOAT_2_ASCII(314.159210,
"314.159210");
223 TEST_EXPECT_FLOAT_2_ASCII(31.41592,
"31.415920");
224 TEST_EXPECT_FLOAT_2_ASCII(3.141592,
"3.141592");
225 TEST_EXPECT_FLOAT_2_ASCII(.3141592,
"3.141592e-01");
226 TEST_EXPECT_FLOAT_2_ASCII(.03141592,
"3.141592e-02");
227 TEST_EXPECT_FLOAT_2_ASCII(.003141592,
"3.141592e-03");
228 TEST_EXPECT_FLOAT_2_ASCII(.0003141592,
"3.141592e-04");
229 TEST_EXPECT_FLOAT_2_ASCII(.00003141592,
"3.141592e-05");
230 TEST_EXPECT_FLOAT_2_ASCII(
M_PI,
"3.141593");
232 TEST_EXPECT_FLOAT_2_ASCII(1/2.0,
"0.5");
233 TEST_EXPECT_FLOAT_2_ASCII(1/3.0,
"3.333333e-01");
234 TEST_EXPECT_FLOAT_2_ASCII(1/4.0,
"0.25");
235 TEST_EXPECT_FLOAT_2_ASCII(1/5.0,
"0.2");
236 TEST_EXPECT_FLOAT_2_ASCII(1/6.0,
"1.666667e-01");
238 TEST_EXPECT_FLOAT_2_ASCII(37550000.0,
"3.755e+07");
239 TEST_EXPECT_FLOAT_2_ASCII(3755000.0,
"3.755e+06");
240 TEST_EXPECT_FLOAT_2_ASCII(375500.0,
"375500");
241 TEST_EXPECT_FLOAT_2_ASCII(37550.0,
"37550");
242 TEST_EXPECT_FLOAT_2_ASCII(3755.0,
"3755");
243 TEST_EXPECT_FLOAT_2_ASCII(375.5,
"375.5");
244 TEST_EXPECT_FLOAT_2_ASCII(37.55,
"37.55");
245 TEST_EXPECT_FLOAT_2_ASCII(3.755,
"3.755");
246 TEST_EXPECT_FLOAT_2_ASCII(0.3755,
"0.3755");
247 TEST_EXPECT_FLOAT_2_ASCII(0.03755,
"0.03755");
248 TEST_EXPECT_FLOAT_2_ASCII(0.003755,
"0.003755");
249 TEST_EXPECT_FLOAT_2_ASCII(0.0003755,
"0.0003755");
250 TEST_EXPECT_FLOAT_2_ASCII(0.00003755,
"3.755e-05");
251 TEST_EXPECT_FLOAT_2_ASCII(0.000003755,
"3.755e-06");
253 TEST_EXPECT_FLOAT_2_ASCII(1000.0*1000.0*1000.0,
"1e+09");
254 TEST_EXPECT_FLOAT_2_ASCII(25000.0*25000.0*25000.0,
"1.5625e+13");
261 void TEST_fail_address_sanitizer() {
266 printf(
"array[5]=%i\n", array[5]);
271 void TEST_fail_undef_sanitizer() {
283 printf(
"o=%i u=%i\n", o, u);
289 printf(
"z1=%i z2=%i\n", z1, z2);
295 void TEST_fail_leak_sanitizer() {
297 printf(
"p[3]=%i\n", p[3]);
305 void TEST_StrUniquifier() {
bool GB_is_executablefile(const char *path)
void ARB_warn_about_unwanted_chars(const char *path, const char *path_description)
const char * ARB_getenv_ignore_empty(const char *envvar)
char * ARB_strdup(const char *str)
const char * GBS_global_string(const char *templat,...)
char buffer[MESSAGE_BUFFERSIZE]
const char * ARB_float_2_ascii(const float f)
static HelixNrInfo * start
char * ARB_executable(const char *exe_name, const char *path)
void GB_warningf(const char *templat,...)
const char * GBS_readable_size(unsigned long long size, const char *unit_suffix)
const char * GBS_readable_timediff(size_t seconds)
#define __ATTR__REDUCED_OPTIMIZE
char ARB_path_contains_unwanted_chars(const char *path)
#define TEST_EXPECT_EQUAL(expr, want)
GB_write_int const char s