Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/sfio/tprintf.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "sftest.h"
21
22
typedef struct _coord_
23
{ int x;
24
int y;
25
} Coord_t;
26
27
Coord_t Coord;
28
29
#if __STD_C
30
int coordprint(Sfio_t* f, Void_t* v, Sffmt_t* fe)
31
#else
32
int coordprint(f, v, fe)
33
Sfio_t* f;
34
Void_t* v;
35
Sffmt_t* fe;
36
#endif
37
{
38
char type[128];
39
Coord_t* cp;
40
char* s;
41
42
if(fe->fmt != 'c')
43
return -1;
44
45
cp = va_arg(fe->args,Coord_t*);
46
memcpy(type,fe->t_str,fe->n_str); type[fe->n_str] = 0;
47
s = *((char**)v) = sfprints(type,cp->x,cp->y);
48
fe->fmt = 's';
49
fe->size = strlen(s);
50
fe->flags |= SFFMT_VALUE;
51
return 0;
52
}
53
54
typedef union Value_u
55
{
56
unsigned char c;
57
short h;
58
int i;
59
long l;
60
Sflong_t ll;
61
Sfdouble_t ld;
62
double d;
63
float f;
64
char *s;
65
int *ip;
66
char **p;
67
} Value_t;
68
69
#if __STD_C
70
int nulprint(Sfio_t* f, Void_t* val, Sffmt_t* fe)
71
#else
72
int nulprint(f, val, fe)
73
Sfio_t* f;
74
Void_t* val;
75
Sffmt_t* fe;
76
#endif
77
{
78
if(fe->fmt == 'Z')
79
{ fe->fmt = 'c';
80
fe->size = -1;
81
fe->base = -1;
82
fe->flags &= ~SFFMT_LONG;
83
fe->flags |= SFFMT_VALUE;
84
((Value_t*)val)->l = 0x04050607;
85
((Value_t*)val)->c = 0;
86
}
87
else if(fe->fmt == 'Y')
88
{ fe->fmt = 'c';
89
fe->size = -1;
90
fe->base = ':';
91
fe->flags &= ~SFFMT_LONG;
92
fe->flags |= SFFMT_VALUE;
93
((Value_t*)val)->s = "abc";
94
}
95
return 0;
96
}
97
98
static int OXcount;
99
static char* OXstr = "abc";
100
#if __STD_C
101
int DOXSprint(Sfio_t* f, Void_t* v, Sffmt_t* fe)
102
#else
103
int DOXSprint(f, v, fe)
104
Sfio_t* f;
105
Void_t* v;
106
Sffmt_t* fe;
107
#endif
108
{
109
OXcount += 1;
110
111
switch(fe->fmt)
112
{
113
case 'd' :
114
*((int*)v) = 10;
115
fe->flags |= SFFMT_VALUE;
116
return 0;
117
118
case 'O' :
119
fe->fmt = 'o';
120
*((int*)v) = 11;
121
fe->flags |= SFFMT_VALUE;
122
return 0;
123
124
case 'X' :
125
fe->fmt = 'x';
126
*((int*)v) = 12;
127
fe->flags |= SFFMT_VALUE;
128
return 0;
129
130
case 's':
131
*((char**)v) = OXstr;
132
fe->flags |= SFFMT_VALUE;
133
return 0;
134
}
135
136
return 0;
137
}
138
139
#if __STD_C
140
int abprint(Sfio_t* f, Void_t* v, Sffmt_t* fe)
141
#else
142
int abprint(f, v, fe)
143
Sfio_t* f;
144
Void_t* v;
145
Sffmt_t* fe;
146
#endif
147
{
148
switch(fe->fmt)
149
{
150
case 'a' :
151
fe->fmt = 'u';
152
return 0;
153
case 'b' :
154
fe->fmt = 'd';
155
return 0;
156
case 'y' : /* test return value of extension function */
157
fe->size = 10;
158
fe->fmt = 's';
159
return 0;
160
case 'Y' : /* terminate format processing */
161
default :
162
return -1;
163
}
164
}
165
166
#if __STD_C
167
int intarg(Sfio_t* f, Void_t* val, Sffmt_t* fe)
168
#else
169
int intarg(f, val, fe)
170
Sfio_t* f;
171
Void_t* val;
172
Sffmt_t* fe;
173
#endif
174
{ static int i = 1;
175
*((int*)val) = i++;
176
fe->flags |= SFFMT_VALUE;
177
return 0;
178
}
179
180
#if __STD_C
181
int shortarg(Sfio_t* f, Void_t* val, Sffmt_t* fe)
182
#else
183
int shortarg(f, val, fe)
184
Sfio_t* f;
185
Void_t* val;
186
Sffmt_t* fe;
187
#endif
188
{ static short i = -2;
189
190
*((short*)val) = i++;
191
fe->size = sizeof(short);
192
fe->flags |= SFFMT_VALUE;
193
194
return 0;
195
}
196
197
#if __STD_C
198
int transarg(Sfio_t* f, Void_t* val, Sffmt_t* fe)
199
#else
200
int transarg(f, val, fe)
201
Sfio_t* f;
202
Void_t* val;
203
Sffmt_t* fe;
204
#endif
205
{
206
switch(fe->fmt)
207
{ case 'D' :
208
fe->fmt = 'd'; return 0;
209
case 'O' :
210
fe->fmt = 'o'; return 0;
211
case 'F' :
212
fe->fmt = 'f'; return 0;
213
case 'S' :
214
fe->fmt = 's'; return 0;
215
case 'C' :
216
fe->fmt = 'c'; return 0;
217
default : return -1;
218
}
219
}
220
221
#if __STD_C
222
void stkprint(char* buf, int n, char* form, ...)
223
#else
224
void stkprint(buf,n,form,va_alist)
225
char* buf;
226
int n;
227
char* form;
228
va_dcl
229
#endif
230
{ va_list args;
231
Sffmt_t fe;
232
#if __STD_C
233
va_start(args,form);
234
#else
235
va_start(args);
236
#endif
237
fe.form = form;
238
va_copy(fe.args,args);
239
fe.extf = NIL(Sffmtext_f);
240
fe.eventf = NIL(Sffmtevent_f);
241
sfsprintf(buf,n,"%! %d %d",&fe,3,4);
242
va_end(args);
243
}
244
245
tmain()
246
{
247
char buf1[1024], buf2[1024], *list[4], *s;
248
double x=0.0051, y;
249
double pnan, nnan, pinf, ninf, pnil, nnil;
250
Sfdouble_t pnanl, nnanl, pinfl, ninfl, pnill, nnill;
251
int i, j;
252
long k;
253
Sffmt_t fe;
254
Sfio_t* f;
255
256
f = sfopen(NIL(Sfio_t*), tstfile("sf", 0), "w+");
257
sfsetbuf(f,buf1,10);
258
sfprintf(f,"%40s\n","0123456789");
259
sfsprintf(buf2,sizeof(buf2),"%40s","0123456789");
260
sfseek(f,(Sfoff_t)0,0);
261
if(!(s = sfgetr(f,'\n',1)) )
262
terror("Failed getting string");
263
if(strcmp(s,buf2) != 0)
264
terror("Failed formatting %%s");
265
266
sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x", 10, 11, 11);
267
sfsprintf(buf2,sizeof(buf2),"%2$4d %1$4o %1$4x", 11, 10);
268
if(strcmp(buf1,buf2) != 0)
269
terror("Failed testing $position");
270
271
sfsprintf(buf1,sizeof(buf1),"%d %1$d %.*d %1$d", 10, 5, 300);
272
sfsprintf(buf2,sizeof(buf2),"%d %1$d %3$.*2$d %1$d", 10, 5, 300);
273
if(strcmp(buf1,buf2) != 0)
274
terror("Failed testing $position with precision");
275
276
fe.version = SFIO_VERSION;
277
fe.form = NIL(char*);
278
fe.extf = DOXSprint;
279
fe.eventf = NIL(Sffmtevent_f);
280
281
sfsprintf(buf1,sizeof(buf1),"%4d %4o %4x %4o %4x %s", 10, 11, 12, 11, 10, "abc");
282
sfsprintf(buf2,sizeof(buf2),"%!%2$4d %3$4O %4$4X %3$4O %2$4x %5$s", &fe);
283
if(strcmp(buf1,buf2) != 0)
284
terror("Failed testing $position2");
285
if(OXcount != 4)
286
terror("Failed OXprint called wrong number of times %d",OXcount);
287
288
sfsprintf(buf1,sizeof(buf1),"%6.2f",x);
289
if(strcmp(buf1," 0.01") != 0)
290
terror("%%f rounding wrong");
291
292
fe.version = SFIO_VERSION;
293
fe.form = NIL(char*);
294
fe.extf = abprint;
295
fe.eventf = NIL(Sffmtevent_f);
296
sfsprintf(buf1,sizeof(buf1),"%%sX%%d%..4u %..4d9876543210",-1,-1);
297
sfsprintf(buf2,sizeof(buf2),"%!%%sX%%d%..4a %..4b%y%Yxxx",
298
&fe, -1, -1, "9876543210yyyy" );
299
if(strcmp(buf1,buf2) != 0)
300
terror("%%!: Extension function failed1");
301
302
fe.form = NIL(char*);
303
fe.extf = intarg;
304
sfsprintf(buf1,sizeof(buf1),"%d %d%",1,2);
305
sfsprintf(buf2,sizeof(buf2),"%!%d %d%",&fe);
306
if(strcmp(buf1,buf2) != 0)
307
terror("%%!: Extension function failed2");
308
309
fe.form = NIL(char*);
310
sfsprintf(buf1,sizeof(buf1),"%d %d%%",3,4);
311
sfsprintf(buf2,sizeof(buf2),"%!%d %d%%",&fe);
312
if(strcmp(buf1,buf2) != 0)
313
terror("%%!: Extension function failed3");
314
315
fe.form = NIL(char*);
316
fe.extf = shortarg;
317
sfsprintf(buf1,sizeof(buf1),"%hu %ho %hi %hu %ho %hd", -2, -1, 0, 1, 2, 3);
318
sfsprintf(buf2,sizeof(buf2),"%!%u %o %i %u %o %d",&fe);
319
if(strcmp(buf1,buf2) != 0)
320
terror("%%!: Extension function failed4");
321
322
/* test extf translation */
323
fe.form = NIL(char*);
324
fe.extf = transarg;
325
sfsprintf(buf1,sizeof(buf1),"%d %o %f %s %c", -1, -1, -1., "s", 'c');
326
sfsprintf(buf2,sizeof(buf2),"%!%D %O %F %S %C",&fe, -1, -1, -1., "s", 'c');
327
if(strcmp(buf1,buf2) != 0)
328
terror("%%!: Extension function failed5");
329
330
k = 1234567890;
331
sfsprintf(buf1,sizeof(buf1),"%I*d",sizeof(k),k);
332
if(strcmp(buf1,"1234567890") != 0)
333
terror("%%I*d failed");
334
335
Coord.x = 5;
336
Coord.y = 7;
337
sfsprintf(buf1,sizeof(buf1),"%d %d",Coord.x,Coord.y);
338
339
fe.form = NIL(char*);
340
fe.extf = coordprint;
341
sfsprintf(buf2,sizeof(buf2),"%!%(%d %d)c",&fe,&Coord);
342
if(strcmp(buf1,buf2) != 0)
343
terror("%%()c `%s' != `%s'", buf1, buf2);
344
345
fe.form = NIL(char*);
346
fe.extf = nulprint;
347
buf2[0] = buf2[1] = buf2[2] = buf2[3] = buf2[4] = 3;
348
sfsprintf(buf2,sizeof(buf2),"%!\001%Z\002",&fe);
349
if(buf2[0]!=1||buf2[1]!=0||buf2[2]!=2||buf2[3]!=0||buf2[4]!=3)
350
terror("%%Z <1,0,2,0,3> != <%o,%o,%o,%o,%o>",
351
buf2[0], buf2[1], buf2[2], buf2[3], buf2[4]);
352
353
fe.form = NIL(char*);
354
fe.extf = nulprint;
355
buf2[0] = buf2[1] = buf2[2] = buf2[3] = buf2[4] = 3;
356
sfsprintf(buf2,sizeof(buf2),"%!%c%Z%c",&fe,1,2);
357
if(buf2[0]!=1||buf2[1]!=0||buf2[2]!=2||buf2[3]!=0||buf2[4]!=3)
358
terror("%%Z <1,0,2,0,3> != <%o,%o,%o,%o,%o>",
359
buf2[0], buf2[1], buf2[2], buf2[3], buf2[4]);
360
361
fe.form = NIL(char*);
362
fe.extf = nulprint;
363
sfsprintf(buf2,sizeof(buf2),"%!%Y",&fe);
364
if(strcmp(buf2,"a:b:c"))
365
terror("%%Y a:b:c != %s", buf2);
366
367
sfsprintf(buf1,sizeof(buf1),"%d %d %d %d",1,2,3,4);
368
stkprint(buf2,sizeof(buf2),"%d %d",1,2);
369
if(strcmp(buf1,buf2) != 0)
370
terror("%%!: Stack function failed");
371
372
sfsprintf(buf1,sizeof(buf1),"% +G",-1.2345);
373
sfsprintf(buf2,sizeof(buf2),"-1.2345");
374
if(strcmp(buf1,buf2) != 0)
375
terror("Failed %% +G test");
376
377
if(sizeof(int) == 4 && sizeof(short) == 2)
378
{ char* s = sfprints("%hx",0xffffffff);
379
if(!s || strcmp(s,"ffff") != 0)
380
terror("Failed %%hx test");
381
382
s = sfprints("%I2x",0xffffffff);
383
if(!s || strcmp(s,"ffff") != 0)
384
terror("Failed %%I2x test");
385
}
386
387
if(sizeof(int) == 4 && sizeof(char) == 1)
388
{ char* s = sfprints("%hhx",0xffffffff);
389
if(!s || strcmp(s,"ff") != 0)
390
terror("Failed %%hhx test");
391
392
s = sfprints("%I1x",0xffffffff);
393
if(!s || strcmp(s,"ff") != 0)
394
terror("Failed %%I1x test");
395
}
396
397
sfsprintf(buf1,sizeof(buf1),"%#..16d",-0xabc);
398
if(strcmp(buf1,"-16#abc") != 0)
399
terror("Failed %%..16d test");
400
401
sfsprintf(buf1,sizeof(buf1),"%#..16lu",(long)0xc2c01576);
402
if(strcmp(buf1,"16#c2c01576") != 0)
403
terror("Failed %%..16u test");
404
405
sfsprintf(buf1,sizeof(buf1),"%0#4o",077);
406
if(strcmp(buf1,"0077") != 0)
407
terror("Failed %%0#4o test");
408
409
sfsprintf(buf1,sizeof(buf1),"%0#4x",0xc);
410
if(strcmp(buf1,"0x000c") != 0)
411
terror("Failed %%0#4x test");
412
413
sfsprintf(buf1,sizeof(buf1),"%c%c%c",'a','b','c');
414
if(strcmp(buf1,"abc") != 0)
415
terror("Failed %%c test");
416
417
sfsprintf(buf1,sizeof(buf1),"%.4c",'a');
418
if(strcmp(buf1,"aaaa") != 0)
419
terror("Failed %%.4c test");
420
421
sfsprintf(buf1,sizeof(buf1),"%hd%c%hd%ld",(short)1,'1',(short)1,1L);
422
if(strcmp(buf1,"1111") != 0)
423
terror("Failed %%hd test");
424
425
sfsprintf(buf1,sizeof(buf1),"%10.5E",(double)0.0000625);
426
if(strcmp(buf1,"6.25000E-05") != 0)
427
terror("Failed %%E test");
428
429
sfsprintf(buf1,sizeof(buf1),"%10.5f",(double)0.0000625);
430
if(strcmp(buf1," 0.00006") != 0)
431
terror("Failed %%f test");
432
433
sfsprintf(buf1,sizeof(buf1),"%10.5G",(double)0.0000625);
434
if(strcmp(buf1," 6.25E-05") != 0)
435
terror("Failed %%G test");
436
437
list[0] = "0";
438
list[1] = "1";
439
list[2] = "2";
440
list[3] = 0;
441
sfsprintf(buf1,sizeof(buf1),"%..*s", ',', list);
442
if(strcmp(buf1,"0,1,2") != 0)
443
terror("Failed %%..*s test");
444
445
sfsprintf(buf1,sizeof(buf1),"%.2.*c", ',', "012");
446
if(strcmp(buf1,"00,11,22") != 0)
447
terror("Failed %%..*c test");
448
449
sfsprintf(buf1,sizeof(buf1),"A%.0dB", 0);
450
if(strcmp(buf1,"AB") != 0)
451
terror("Failed precision+0 test");
452
453
sfsprintf(buf1,sizeof(buf1),"A%.0dB", 1);
454
if(strcmp(buf1,"A1B") != 0)
455
terror("Failed precision+1 test");
456
457
sfsprintf(buf1,sizeof(buf1),"A%4.0dB", 12345);
458
if(strcmp(buf1,"A12345B") != 0)
459
terror("Failed exceeding width test");
460
461
sfsprintf(buf1,sizeof(buf1),"A%3dB",33);
462
if(strcmp(buf1,"A 33B") != 0)
463
terror("Failed justification test");
464
465
sfsprintf(buf1,sizeof(buf1),"A%04dB",-1);
466
if(strcmp(buf1,"A-001B") != 0)
467
terror("Failed zero filling test");
468
469
sfsprintf(buf1,sizeof(buf1),"A%+04dB",1);
470
if(strcmp(buf1,"A+001B") != 0)
471
terror("Failed signed and zero-filled test");
472
473
sfsprintf(buf1,sizeof(buf1),"A% .0dB", -1);
474
if(strcmp(buf1,"A-1B") != 0)
475
terror("Failed blank and precision test");
476
477
sfsprintf(buf1,sizeof(buf1),"A%+ .0dB", 1);
478
if(strcmp(buf1,"A+1B") != 0)
479
terror("Failed +,blank and precision test");
480
481
sfsprintf(buf1,sizeof(buf1),"A%010.2fB", 1.2);
482
if(strcmp(buf1,"A0000001.20B") != 0)
483
terror("Failed floating point and zero-filled test");
484
485
sfsprintf(buf1,sizeof(buf1),"A%-010.2fB", 1.2);
486
if(strcmp(buf1,"A1.20 B") != 0)
487
terror("Failed floating point and left justification test");
488
489
sfsprintf(buf1,sizeof(buf1),"A%-#XB", 0xab);
490
if(strcmp(buf1,"A0XABB") != 0)
491
terror("Failed %%-#X conversion test");
492
493
#if !_ast_intmax_long
494
{ Sflong_t ll;
495
char buf[128];
496
char* s = sfprints("%#..16llu",~((Sflong_t)0));
497
sfsscanf(s,"%lli", &ll);
498
if(ll != (~((Sflong_t)0)) )
499
terror("Failed inverting printf/scanf Sflong_t");
500
501
s = sfprints("%#..18lld",~((Sflong_t)0));
502
sfsscanf(s,"%lli", &ll);
503
if(ll != (~((Sflong_t)0)) )
504
terror("Failed inverting printf/scanf Sflong_t");
505
506
s = sfprints("%#..lli",~((Sflong_t)0));
507
sfsscanf(s,"%lli", &ll);
508
if(ll != (~((Sflong_t)0)) )
509
terror("Failed inverting printf/scanf Sflong_t");
510
511
sfsprintf(buf,sizeof(buf), "%llu", (~((Sflong_t)0)/2) );
512
s = sfprints("%Iu", (~((Sflong_t)0)/2) );
513
if(strcmp(buf,s) != 0)
514
terror("Failed conversion with I flag");
515
516
if(sizeof(Sflong_t)*8 == 64)
517
{ s = sfprints("%I64u",(~((Sflong_t)0)/2) );
518
if(strcmp(buf,s) != 0)
519
terror("Failed conversion with I64 flag");
520
}
521
}
522
#endif
523
524
i = (int)(~(~((unsigned int)0) >> 1));
525
s = sfprints("%d",i);
526
j = atoi(s);
527
if(i != j)
528
terror("Failed converting highbit");
529
530
for(i = -10000; i < 10000; i += 123)
531
{ s = sfprints("%d",i);
532
j = atoi(s);
533
if(j != i)
534
terror("Failed integer conversion");
535
}
536
537
/* test I flag for strings */
538
{ char *ls[3];
539
ls[0] = "0123456789";
540
ls[1] = "abcdefghij";
541
ls[2] = 0;
542
s = sfprints("%I5..*s", 0, ls);
543
if(strcmp(s, "01234abcde") != 0)
544
terror("Failed I flag with %%s");
545
}
546
547
/* test justification */
548
sfsprintf(buf1,sizeof(buf1),"%-10.5s","abcdefghij");
549
sfsprintf(buf2,sizeof(buf2),"%*.5s",-10,"abcdefghij");
550
if(strcmp(buf1,buf2) != 0)
551
terror("Left-justification is wrong");
552
553
sfsprintf(buf1,sizeof(buf1),"%10.5s","abcdefghij");
554
sfsprintf(buf2,sizeof(buf2),"%*.5s",10,"abcdefghij");
555
if(strcmp(buf1,buf2) != 0)
556
terror("Justification is wrong");
557
558
/* testing x/open compliant with respect to precision */
559
sfsprintf(buf1, sizeof(buf1),
560
"%.d %.hi %.lo %.f %.e %.g %.g %.g %.g %.g %.s %.d %.hi %.lo|",
561
1345,
562
1234,
563
1234567890,
564
321.7654321,
565
321.7654321,
566
-0.01,
567
0.01,
568
1e-5,
569
1.4,
570
-1.4,
571
"test-string",
572
0,
573
0,
574
0L);
575
576
if(strcmp(buf1,"1345 1234 11145401322 322 3e+02 -0.01 0.01 1e-05 1 -1 |") )
577
terror("Precision not set to zero as required after a dot");
578
579
/* test %#c to print C-style characters */
580
sfsprintf(buf1, sizeof(buf1), "%#.2c%#.2c", '\n', 255);
581
if(strcmp(buf1, "\\n\\n\\377\\377") != 0)
582
terror("%%#c formatting failed");
583
584
/* test printing of signed integer of length 1 */
585
#if defined(__STDC__)
586
{ signed char c = -1;
587
sfsprintf(buf1, sizeof(buf1), "%I1d", c);
588
if(strcmp(buf1, "-1") != 0)
589
terror("%%I1d formatting failed");
590
}
591
#endif
592
593
pnan = strtod("NaN", NIL(char));
594
nnan = strtod("-NaN", NIL(char));
595
pinf = strtod("Inf", NIL(char));
596
ninf = strtod("-Inf", NIL(char));
597
pnil = strtod("0.0", NIL(char));
598
nnil = strtod("-0.0", NIL(char));
599
sfsprintf(buf1, sizeof(buf1), "%g %g %g %g %g %g", pnan, nnan, pinf, ninf, pnil, nnil);
600
if (strcmp(buf1, "nan -nan inf -inf 0 -0") != 0)
601
terror("double NaN Inf 0.0 error: %s", buf1);
602
sfsprintf(buf1, sizeof(buf1), "%G %G %G %G %G %G", pnan, nnan, pinf, ninf, pnil, nnil);
603
if (strcmp(buf1, "NAN -NAN INF -INF 0 -0") != 0)
604
terror("double NaN Inf 0.0 error: %s", buf1);
605
sfsprintf(buf1, sizeof(buf1), "%05g %05g %05g %05g %05g %05g", pnan, nnan, pinf, ninf, pnil, nnil);
606
if (strcmp(buf1, " nan -nan inf -inf 00000 -0000") != 0)
607
terror("double NaN Inf 0.0 error: %s", buf1);
608
609
pnanl = strtold("NaN", NIL(char));
610
nnanl = strtold("-NaN", NIL(char));
611
pinfl = strtold("Inf", NIL(char));
612
ninfl = strtold("-Inf", NIL(char));
613
pnill = strtold("0.0", NIL(char));
614
nnill = strtold("-0.0", NIL(char));
615
sfsprintf(buf1, sizeof(buf1), "%Lg %Lg %Lg %Lg %Lg %Lg", pnanl, nnanl, pinfl, ninfl, pnill, nnill);
616
if (strcmp(buf1, "nan -nan inf -inf 0 -0") != 0)
617
terror("long double NaN Inf 0.0 error: %s", buf1);
618
sfsprintf(buf1, sizeof(buf1), "%LG %LG %LG %LG %LG %LG", pnanl, nnanl, pinfl, ninfl, pnill, nnill);
619
if (strcmp(buf1, "NAN -NAN INF -INF 0 -0") != 0)
620
terror("long double NaN Inf 0.0 error: %s", buf1);
621
sfsprintf(buf1, sizeof(buf1), "%05Lg %05Lg %05Lg %05Lg %05Lg %05Lg", pnanl, nnanl, pinfl, ninfl, pnill, nnill);
622
if (strcmp(buf1, " nan -nan inf -inf 00000 -0000") != 0)
623
terror("long double NaN Inf 0.0 error: %s", buf1);
624
625
/* test the sfaprints() function */
626
if((i = sfaprints(&s, "%d", 123)) != 3 || strcmp(s, "123") != 0)
627
terror("sfaprints() failed -- expected \"123\" [3], got \"%s\" [%d]", s, i);
628
free(s);
629
630
/* test 64-bit linux %g */
631
sfsprintf(buf1, sizeof(buf1), "%1.15g", (double)987654321098782.0);
632
if(strcmp(buf1, "987654321098782") != 0)
633
terror("(double)987654321098782.0 %%1.15g format error: %s", buf1);
634
635
texit(0);
636
}
637
638