69 long long diff, l1,l2;
84 printf(
"WARN: length mismatch (%d) != (%d)\n",
86 printf(
" str1:[%s]\n", save1);
87 printf(
" str2:[%s]\n", save2);
92 while( (c1 = *str1) && (c2 = *str2) )
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);
112 if(c1 ==
'.' || c1 ==
' ' || c1 ==
'-' || c1 ==
'+')
122 while( (c1 = *str1) && (c2 = *str2) )
124 if( c1 ==
'.' && c2 ==
'.' )
135 if(!nzflag && (c1 !=
'0' || c2 !=
'0'))
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);
169 if(c1 ==
'e' || c1 ==
'E')
171 if(
strcmp(str1,str2) != 0)
173 printf(
"WARN: exponent mismatch at offset:(%d)\n", count);
174 printf(
" str1:[%s]\n", save1);
175 printf(
" str2:[%s]\n", save2);
197 static void _putc_fn(
struct _printf_t *p,
char ch)
207 int t_printf(
const char *format, ...)
217 va_start(va, format);
234 int t_vsnprintf(
char* str,
size_t size,
const char *format, va_list va)
257 int display_good = 0;
268 void tp(
const char *format, ...)
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);
297 printf(
"ERROR: empty format\n");
314 if(f ==
'l' || f ==
'h')
326 va_start(va, format);
327 len =
vsnprintf(str0,
sizeof(str0)-1, fmt, va);
332 va_start(va, format);
333 len =
vsnprintf(str1,
sizeof(str1)-1, format, va);
338 va_start(va, format);
339 len = t_vsnprintf(str2,
sizeof(str2)-1, format, va);
346 if(f ==
'g' || f ==
'G' || f ==
'e' || f ==
'E' || f ==
'f' || f ==
'F')
354 if(
sizeof(
double) == 8)
356 else if(
sizeof(
double) == 4)
360 fprintf(
stderr,
"Unexpected size of double:%d\n", (
int)
sizeof(
double));
365 error = numcmp(str1,str2,digits);
369 if(error < 0 || error > 14LL)
371 printf(
"ERROR: [%s], [%s]\n", format, str0);
374 printf(
" error:%lld\n", error);
382 printf(
"OK: [%s], [%s]\n", format, str0);
389 if(
strcmp(str1,str2) != 0)
391 printf(
"ERROR: [%s], [%s]\n", format, str0);
401 printf(
"OK: [%s], [%s]\n", format, str0);
420 void random_tests(
int flag,
char *size)
436 char *signop =
"+- 0";
440 memset(format,0,128);
456 signind = drand48() * 3.99999;
461 if(flag ==
'e' || flag ==
'f' )
476 if(
sizeof(
double) == 8)
480 else if(
sizeof(
double) == 4)
486 fprintf(
stderr,
"Unexpected size of double:%d\n",(
int)
sizeof(
double));
489 width = drand48() * 2.0 * digits;
490 prec = drand48() * 2.0 * digits;
492 snprintf(format,
sizeof(format)-1,
"%%%c%d.%d%c", signop[signind], width, prec, flag);
494 snprintf(format,
sizeof(format)-1,
"%%%c%d%c", signop[signind], width, flag);
497 exp10 = ((drand48() * 2.0) - 1.0) * (double) (digits * 2);
498 scale =
iexp(10.0, exp10);
499 dnum = ( sign * drand48() * scale);
504 if(
strcmp(size,
"short") == 0)
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);
512 snprintf(format,
sizeof(format)-1,
"%%%c%d.%dh%c", signop[signind], width, prec, flag);
514 snprintf(format,
sizeof(format)-1,
"%%%c%dh%c", signop[signind], width, flag);
517 else if(
strcmp(size,
"int") == 0)
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);
525 snprintf(format,
sizeof(format)-1,
"%%%c%d.%d%c", signop[signind], width, prec, flag);
527 snprintf(format,
sizeof(format)-1,
"%%%c%d%c", signop[signind], width, flag);
530 else if(
strcmp(size,
"long") == 0)
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);
538 snprintf(format,
sizeof(format)-1,
"%%%c%d.%dl%c", signop[signind], width, prec, flag);
540 snprintf(format,
sizeof(format)-1,
"%%%c%dl%c", signop[signind], width, flag);
543 else if(
strcmp(size,
"long long") == 0)
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);
551 snprintf(format,
sizeof(format)-1,
"%%%c%d.%dll%c", signop[signind], width, prec, flag);
553 snprintf(format,
sizeof(format)-1,
"%%%c%dll%c", signop[signind], width, flag);
573 printf(
"=======================\n");
574 printf(
"Start of Manual tests\n");
593 tp(
"% - .5lu", -123);
603 tp(
"% - .5ld", -123);
633 tp(
"%+0f", -0.196764);
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);
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);
668 tp(
"%+014.8f", 3.14159265358979);
669 tp(
"%+14.8f", 3.141);
670 tp(
"% .2f", -1234567.89);
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);
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);
748 printf(
"End of Manual tests\n");
749 printf(
"=======================\n");
757 int main(
int argc,
char *argv[])
765 #ifdef __SIZEOF_INT128__ 771 char *intops =
"duxXo";
772 char *sizeops[] = {
"short",
"int",
"long",
"long long",
NULL };
773 char *floatops =
"fe";
775 printf(
"=======================\n");
776 printf(
"Start of Manual tests\n");
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) );
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");
793 #ifdef __SIZEOF_INT128__ 794 printf(
"=======================\n");
795 printf(
"Start of 128 bit int tests\n");
800 t_printf(
"2**%03d = [%I128d]\n", i, num128);
804 printf(
"=======================\n");
806 printf(
"=======================\n");
807 printf(
"Start of 128 bit int tests - 40 field width\n");
811 t_printf(
"2**%03d = [%40I128d]\n", i, num128);
815 printf(
"=======================\n");
817 printf(
"=======================\n");
818 printf(
"Start of 128 bit int tests - 40 field width and leading 0's\n");
822 t_printf(
"2**%03d = [%+040I128d]\n", i, num128);
826 printf(
"=======================\n");
834 printf(
"Start of random tests\n");
838 for(size=0;sizeops[size];++size)
840 for(k=0;intops[k];++k)
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");
855 for(k=0;floatops[k];++k)
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");
870 printf(
"=======================\n");
871 printf(
"testing binary leading 1's\n");
884 printf(
"=================================\n");
885 printf(
"testing binary trailing 1's\n");
897 printf(
"=================================\n");
898 printf(
"testing base 10 9's\n");
902 if(lnum & (1
L << ((
sizeof(lnum)*8)-1)))
912 printf(
"=================================\n");
MEMSPACE int vsnprintf(char *str, size_t size, const char *format, va_list va)
vsnprintf function
MEMSPACE int WEAK_ATR strcmp(const char *str, const char *pat)
Compare two strings.
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
MEMSPACE void _printf_fn(printf_t *fn, __memx const char *fmt, va_list va)
vsnprintf function
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...
#define snprintf(s, size, format, args...)
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
int main(int argc, char *argv[])
Math IO functions, and verious conversion code with floating point support.
MEMSPACE double iexp(double num, int exp)
MEMSPACE long long strtoll(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
MEMSPACE int WEAK_ATR isdigit(int c)
test if a character is a digit
MEMSPACE int printf(const char *format,...)
void(* put)(struct _printf_t *, char)
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...
undefine any potential macro version of these functions