X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f X-Recipient: djgpp-workers AT delorie DOT com X-Authenticated: #27081556 X-Provags-ID: V01U2FsdGVkX18jPAQZ5PYjKA45uaA9DU3v0bDyenyNejucaAGqkf IdPH8bOozlIas2 From: Juan Manuel Guerrero To: djgpp-workers AT delorie DOT com Subject: Re: Implementation of certain conversion specifiers in _doprnt (patch #3) Date: Thu, 24 Apr 2008 16:30:11 +0200 User-Agent: KMail/1.9.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804241630.12214.juan.guerrero@gmx.de> X-Y-GMX-Trusted: 0 Reply-To: djgpp-workers AT delorie DOT com The goal of this patch is to implement the %[aAF] convertion specifiers in _doprnt(). Also some other things are implemented like the systematic substitution of type punning unions with the ones defined in ieee.h. Regards, Juan M. Guerrero 2008-04-23 Juan Manuel Guerrero Diffs against djgpp CVS head of 2008-04-23. * src/libc/ansi/stdio/doprnt.c: Implementation of %[aA] conversion specifier. * src/libc/ansi/stdio/printf.txh: Description of the %[aA] conversion specifier added. * src/docs/kb/wc204.txi: Info about %[aAF] convertion specifiers for doprnt.c and printf family of functions added. * tests/libc/ansi/stdio/makefile: Added printf3.c to test %[aA] and other conversion specifiers. * tests/libc/ansi/stdio/printf3.c: Tests for %[aA] and other conversion specifiers. diff -aprNU3 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi --- djgpp.orig/src/docs/kb/wc204.txi 2008-04-24 15:08:40 +0000 +++ djgpp/src/docs/kb/wc204.txi 2008-04-24 15:09:08 +0000 @@ -1131,3 +1131,9 @@ return for the following special numbers @code{Pseudo-Denormal}, @code{Pseudo-NaN}, @code{Pseudo-Infinity}, @code{Pseudo-Zero} and denormalized numbers @code{nan} or @code{NAN} instead of @code{Unnormal}. + +@findex _doprnt AT r{, and C99 conversion specifiers} +@findex printf AT r{, and C99 conversion specifiers} +The @code{a}, @code{A} and @code{F} conversion specifiers +are now supported by @code{_doprnt} and the @code{printf} +family of functions. diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/doprnt.c djgpp/src/libc/ansi/stdio/doprnt.c --- djgpp.orig/src/libc/ansi/stdio/doprnt.c 2008-04-24 15:08:40 +0000 +++ djgpp/src/libc/ansi/stdio/doprnt.c 2008-04-24 15:09:08 +0000 @@ -24,6 +24,13 @@ static char decimal_point; static char thousands_sep; static char *grouping; +#ifndef FALSE +# define FALSE 0 +#endif +#ifndef TRUE +# define TRUE 1 +#endif + /* 11-bit exponent (VAX G floating point) is 308 decimal digits */ #define MAXEXP 308 #define MAXEXPLD 4952 /* this includes subnormal numbers */ @@ -44,6 +51,16 @@ static char *grouping; flags&CHARINT ? (char basetype)va_arg(argp, int) : \ (basetype)va_arg(argp, int) +#define CONVERT(type, value, base, string, case) \ + do { \ + const char *digit = (case) ? UPPER_DIGITS : LOWER_DIGITS; \ + register type _value = (type)(value); \ + \ + do { \ + *--(string) = digit[(_value) % (base)]; \ + } while ((_value) /= (base)); \ + } while (0) + #define IS_FINITE(x) (((x).ldt.exponent < 0x7FFFU && (x).ldt.exponent > 0x0000U && (x).ldt.mantissah & 0x80000000UL) \ || ((x).ldt.exponent == 0x0000U && !((x).ldt.mantissah & 0x80000000UL))) #define IS_ZERO(x) ((x).ldt.exponent == 0x0U && (x).ldt.mantissah == 0x0UL && (x).ldt.mantissal == 0x0UL) @@ -90,6 +107,8 @@ static int isspeciall(long double d, cha static __inline__ char * __grouping_format(char *string_start, char *string_end, char *buffer_end, int flags); static char NULL_REP[] = "(null)"; +static const char LOWER_DIGITS[] = "0123456789abcdef"; +static const char UPPER_DIGITS[] = "0123456789ABCDEF"; int @@ -101,24 +120,24 @@ _doprnt(const char *fmt0, va_list argp, int n; /* random handy integer */ char *t; /* buffer pointer */ long double _ldouble; /* double and long double precision arguments - %L.[eEfgG] */ + %L.[aAeEfFgG] */ unsigned long long _ulonglong=0; /* integer arguments %[diouxX] */ int base; /* base for [diouxX] conversion */ int dprec; /* decimal precision in [diouxX] */ int fieldsz; /* field size expanded by sign, etc */ int flags; /* flags as above */ - int fpprec; /* `extra' floating precision in [eEfgG] */ + int fpprec; /* `extra' floating precision in [eEfFgG] */ int prec; /* precision from format (%.3d), or -1 */ int realsz; /* field size expanded by decimal precision */ int size; /* size of converted field or string */ int width; /* width from format (%8d), or 0 */ char sign; /* sign prefix (' ', '+', '-', or \0) */ char softsign; /* temporary negative sign for floats */ - const char *digs; /* digits for [diouxX] conversion */ - char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ - int neg_ldouble = 0; /* non-zero if _ldouble is negative */ + char buf[BUF]; /* space for %c, %[diouxX], %[aAeEfFgG] */ + int neg_ldouble = FALSE; /* TRUE if _ldouble is negative */ struct lconv *locale_info; /* current locale information */ + locale_info = localeconv(); decimal_point = locale_info->decimal_point[0]; @@ -131,7 +150,6 @@ _doprnt(const char *fmt0, va_list argp, return (EOF); fmt = fmt0; - digs = "0123456789abcdef"; for (cnt = 0;; ++fmt) { _longdouble_union_t ieee_value; @@ -265,13 +283,21 @@ _doprnt(const char *fmt0, va_list argp, base = 10; flags |= FINITENUMBER; goto number; + case 'A': case 'E': + case 'F': case 'G': flags |= UPPERCASE; + case 'a': case 'e': case 'f': case 'g': flags |= FLOAT; + if (*fmt == 'A' || *fmt == 'a') + { + flags |= HEXPREFIX; + flags &= ~LONGINT; + } if (flags & LONGDBL) _ldouble = va_arg(argp, long double); else @@ -296,6 +322,15 @@ _doprnt(const char *fmt0, va_list argp, { if (flags & LONGINT) prec = DEFLPREC; + else if (flags & HEXPREFIX) + /* + * C99 imposes that precision must be sufficient + * for an exact representation of the mantissa. + * If no explicit precision is given, the required + * precision for exact representation will be + * determinated in the conversion function itself. + */ + prec = -1; else prec = DEFPREC; } @@ -308,7 +343,7 @@ _doprnt(const char *fmt0, va_list argp, { softsign = '-'; _ldouble = -_ldouble; - neg_ldouble = 1; + neg_ldouble = TRUE; } else { @@ -316,12 +351,12 @@ _doprnt(const char *fmt0, va_list argp, if (ieee_value.ldt.sign) { - neg_ldouble = 1; + neg_ldouble = TRUE; if (IS_ZERO(ieee_value) || IS_NAN(ieee_value) || IS_PSEUDO_NUMBER(ieee_value)) softsign = '-'; } else - neg_ldouble = 0; + neg_ldouble = FALSE; } /* * cvt may have to round up past the "start" of the @@ -340,7 +375,7 @@ _doprnt(const char *fmt0, va_list argp, if (softsign || (sign == '+' && neg_ldouble)) sign = '-'; t = *buf ? buf : buf + 1; - base = 10; + base = flags & HEXPREFIX ? 16 : 10; goto pforw; case 'n': if (flags & LONGDBL) @@ -408,7 +443,6 @@ _doprnt(const char *fmt0, va_list argp, flags |= FINITENUMBER; goto nosign; case 'X': - digs = "0123456789ABCDEF"; flags |= UPPERCASE; /* FALLTHROUGH */ case 'x': @@ -442,24 +476,14 @@ _doprnt(const char *fmt0, va_list argp, { /* conversion is done separately since operations with long long are much slower */ -#define CONVERT(type) \ - do { \ - register type _n = (type)_ulonglong; \ - do { \ - *--t = digs[_n % base]; \ - _n /= base; \ - } while (_n); \ - } while (0) if (flags & LONGDBL) - CONVERT(unsigned long long); + CONVERT(unsigned long long, _ulonglong, base, t, flags & UPPERCASE); else - CONVERT(unsigned long); -#undef CONVERT + CONVERT(unsigned long, _ulonglong, base, t, flags & UPPERCASE); if ((flags & ALT) && base == 8 && *t != '0') *--t = '0'; /* octal leading 0 */ } - digs = "0123456789abcdef"; size = buf + BUF - t; pforw: @@ -495,8 +519,8 @@ _doprnt(const char *fmt0, va_list argp, realsz = dprec > fieldsz ? dprec : fieldsz; if (sign) realsz++; - if (flags & HEXPREFIX) - realsz += 2; + if ((flags & HEXPREFIX) && (flags & FINITENUMBER)) + realsz += 2; /* hex leading 0x */ /* right-adjusting blank padding */ if ((flags & (LADJUST | ZEROPAD)) == 0 && width) @@ -505,10 +529,10 @@ _doprnt(const char *fmt0, va_list argp, /* prefix */ if (sign) PUTC(sign); - if (flags & HEXPREFIX) + if ((flags & HEXPREFIX) && (flags & FINITENUMBER)) { PUTC('0'); - PUTC((char)*fmt); + PUTC((*fmt == 'A') ? 'X' : (*fmt == 'a') ? 'x' : (char)*fmt); } /* right-adjusting zero padding */ if ((flags & (LADJUST | ZEROPAD)) == ZEROPAD) @@ -571,15 +595,197 @@ cvtl(long double number, int prec, int f char *startp, char *endp) { char *p, *t; - long double fract=0; + long double fract = 0; int dotrim, expcnt, gformat; - int doextradps=0; /* Do extra decimal places if the precision needs it */ - int doingzero=0; /* We're displaying 0.0 */ + int doextradps = FALSE; /* Do extra decimal places if the precision needs it */ + int doingzero = FALSE; /* We're displaying 0.0 */ long double integer, tmp; if ((expcnt = isspeciall(number, startp, flags))) return(expcnt); + if (fmtch == 'a' || fmtch == 'A') + { + /* + * We are dealing with intel's extended double format. + * The 64-bit mantissa explicitly contains the leading integer binary digit. + * C99 standard defines hex float format as: 0xh.hhhp+ddd + * where h is a hex digit, d is a decimal digit and p represents base 2. + * The 64 bit of the mantissa can be subdivided into 16 nibbles, + * so exact hex representation of the binary coded mantissa is + * possible. To get a single hex digit in the integer part of + * the mantissa the period must be shifted by three places + * to the right if the number is a normalized finite one. + * If it is a denormalized finite number, then it may become necessary + * to shift the period by ont to fifteen places. Accordingly the exponent + * must be adjusted. + */ +#define CHAR_SIZE 8 +#define HEX_DIGIT_SIZE 4 +#define IEEE754_LONG_DOUBLE_BIAS 0x3FFFU + + + long_double_t ip = *(long_double_t *)(void *)&number; + char *fraction_part; + int left_shifts, precision_given, positive_exponent, exponent = ip.exponent; + unsigned long long int mantissa = (unsigned long long int) ip.mantissah << 32 | ip.mantissal; + + p = endp; + t = startp; + precision_given = (prec != -1) ? TRUE : FALSE; + + /* + * Compute the amount of left shifts necessary + * to have one single hex digit (nibble) in the + * integer part of the mantissa. For normalized + * finite numbers these are 3. For denormalized + * finte numbers these will range from 1 to 15. + * Accordingly to these shifts the exponent will + * be adjusted. + */ + left_shifts = 0; /* No shifts for 0.0 */ + if (mantissa) + { + unsigned long long int m = mantissa; + + for (; !(mantissa & 0x8000000000000000ULL); left_shifts++) + mantissa <<= 1; + if (left_shifts) /* Denormalized finite. */ + { + if (precision_given == FALSE) + mantissa = m; + + if (left_shifts < (int)(sizeof(mantissa) * CHAR_SIZE - HEX_DIGIT_SIZE)) + { + /* + * For an exact representation of the mantissa + * there must be a integral number of nibbles + * (hex digit) in the fraction part of the mantissa. + * A fraction part of a nibble will be shifted + * into the integer part of the mantissa. + * The converted mantisssa will look like: + * 0xh.hhhh + * and the exponent will be adjusted accordingly. + */ + unsigned int bin_digits, digits = (sizeof(mantissa) * CHAR_SIZE - 1 - left_shifts) % HEX_DIGIT_SIZE; /* Number of digits that do not build a nibble in the fraction part. */ + + /* + * Shift the period to the left + * until no fraction of a nibble remains + * in the fraction part of the mantissa. + */ + for (bin_digits = 0; bin_digits < digits; bin_digits++) + left_shifts++; + + /* + * If no binary digits are shifted into the integer part, + * then the nibble of the integer part must be filled with zeros. + */ + if (precision_given == TRUE && bin_digits == 0) + mantissa >>= (HEX_DIGIT_SIZE - 1); + } + else + left_shifts = sizeof(mantissa) * CHAR_SIZE - 1; + } + else /* Normalized finite. */ + left_shifts = HEX_DIGIT_SIZE - 1; + } + + /* + * Mantissa. + * The mantissa representation shall be exact + * except that trailing zeros may be omitted. + */ + if (precision_given == TRUE) + { + unsigned int fraction_hex_digits = sizeof(mantissa) * CHAR_SIZE / HEX_DIGIT_SIZE - 1; /* Number of hex digits (nibbles) in the fraction part. */ + + if (prec < (int)fraction_hex_digits) + { + /* + * If requested precision is less than the size of + * the mantissa's fraction do rounding to even. + */ +#define MUST_ROUND_TO_EVEN(value) ((((value) & 0x0FULL) == 0x08ULL) && ((((value) & 0xF0ULL) >> HEX_DIGIT_SIZE) % 2)) + unsigned int n = fraction_hex_digits - prec - 1; /* One nibble more than precision. */ + + mantissa >>= n * HEX_DIGIT_SIZE; /* The least significant nibble will determinate the rounding. */ + if (((mantissa & 0x0FULL) > 0x08ULL) || MUST_ROUND_TO_EVEN(mantissa)) + mantissa += 0x10ULL; /* Round up. */ + mantissa >>= HEX_DIGIT_SIZE; /* Discard least significant nibble used for rounding. */ + + n = fraction_hex_digits - n; + if ((mantissa >> (n * HEX_DIGIT_SIZE)) & 0x01ULL) /* Carry ? */ + { + /* + * The rounding has produced a 2 hex digit long integer part + * of the mantissa, so the mantissa must be shifted to the right + * by one hex digit and the exponent adjusted accordingly. + */ + mantissa >>= HEX_DIGIT_SIZE; + left_shifts -= HEX_DIGIT_SIZE; + } +#undef MUST_ROUND_TO_EVEN + } + } + + CONVERT(unsigned long long int, mantissa, 16, p, fmtch == 'A'); + *t++ = *p++; + *t++ = decimal_point; + + fraction_part = t; + for (; p < endp; *t++ = *p++) + ; + if (precision_given == FALSE) + { + /* + * C99 imposes that, if the precision is omitted, + * the precision must be sufficient for an exact + * representation of the mantissa except that the + * trailing zeros may be omitted. + */ + while (*--t == '0') + ; /* Discart trailing zeros. */ + t++; /* Points to first free place. */ + } + else + while (t - fraction_part < prec && t < endp) + *t++ = '0'; /* Pad with zeros to the right. At the end of the loop points to first free place. */ + if (t[-1] == decimal_point && !(flags & ALT)) + t--; /* Do not output a decimal point. */ + + /* + * Exponent. + */ + if (exponent == 0) + { + if (mantissa) /* Denormalized finite number. */ + exponent = 1 - IEEE754_LONG_DOUBLE_BIAS; + } + else /* Normalized finite number. */ + exponent -= IEEE754_LONG_DOUBLE_BIAS; + exponent -= left_shifts; + if (exponent < 0) + { + exponent = -exponent; + positive_exponent = FALSE; + } + else + positive_exponent = TRUE; + + CONVERT(int, exponent, 10, p, flags & UPPERCASE); + *--p = (positive_exponent) ? '+' : '-'; + *--p = (flags & UPPERCASE) ? 'P' : 'p'; + for (; p < endp; *t++ = *p++) + ; + + return t - startp; + +#undef IEEE754_LONG_DOUBLE_BIAS +#undef HEX_DIGIT_SIZE +#undef CHAR_SIZE + } + dotrim = expcnt = gformat = 0; /* fract = modfl(number, &integer); */ integer = number; @@ -627,9 +833,9 @@ cvtl(long double number, int prec, int f if (integer < 1) { /* If fract is zero the zero before the decimal point is a sig fig */ - if (fract == 0.0) doingzero = 1; + if (fract == 0.0) doingzero = TRUE; /* If fract is non-zero all sig figs are in fractional part */ - else doextradps = 1; + else doextradps = TRUE; } /* * get integer portion of number; put into the end of the buffer. @@ -648,6 +854,7 @@ cvtl(long double number, int prec, int f switch(fmtch) { case 'f': + case 'F': /* reverse integer into beginning of buffer */ if (expcnt) for (; ++p < endp; *t++ = *p); @@ -815,11 +1022,11 @@ cvtl(long double number, int prec, int f */ if (prec || (flags & ALT)) { - dotrim = 1; + dotrim = TRUE; *t++ = decimal_point; } else - dotrim = 0; + dotrim = FALSE; /* if requires more precision and some fraction left */ while (prec && fract) { @@ -828,9 +1035,9 @@ cvtl(long double number, int prec, int f /* If we're not adding 0s * or we are but they're sig figs: * decrement the precision */ - if ((doextradps != 1) || ((int)tmp != 0)) + if ((doextradps != TRUE) || ((int)tmp != 0)) { - doextradps = 0; + doextradps = FALSE; prec--; } } diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/printf.txh djgpp/src/libc/ansi/stdio/printf.txh --- djgpp.orig/src/libc/ansi/stdio/printf.txh 2008-04-24 15:08:36 +0000 +++ djgpp/src/libc/ansi/stdio/printf.txh 2008-04-24 15:09:44 +0000 @@ -5,7 +5,7 @@ @example #include -int printf(const char *format, @dots{}); +int printf(const char *@var{format}, @dots{}); @end example @subheading Description @@ -106,6 +106,17 @@ The conversion type specifier: @table @code +@item a +@itemx A + +A floating point number (float or double) printed in the style +@code{"[-]0xh.hhhhp[+|-]d"}, where @code{h} represents a hexadecimal +digit, @code{d} represents a decimal digit and @code{p} stands for the +base 2. For long double, use @code{"La"} or @code{"LA"}. The case of +the exponent, the case of the letters @code{"abcdef"} and the case of +@code{"x"} matches the specifier case. The representation always has +an exponent. + @item c A single character. @@ -127,6 +138,7 @@ A floating point number (float or double case. The representation always has an exponent. @item f +@itemx F A floating point number (float or double). For long double, use @code{"Lf"}. The representation never has an exponent. @@ -193,12 +205,14 @@ The number of characters written. @subheading Portability -@port-note ansi The @code{D}, @code{O} and @code{U} conversion types -are non-standard. gcc may generate warnings, if you use them. +@port-note ansi The @code{D}, @code{O} and @code{U} conversion type +specifiers are non-standard. gcc may generate warnings, if you use them. + +@port-note ansi-c99 The @code{hh}, @code{j}, @code{t} and @code{z} +conversion qualifiers first appeared in the ANSI C99 standard. -@port-note ansi-c99 The @code{hh}, @code{j}, @code{t} -and @code{z} conversion specifiers first appeared -in the ANSI C99 standard. +@port-note ansi The @code{a}, @code{A} and @code{F} conversion type +specifiers first appeared in the ANSI C99 standard. @portability ansi, posix diff -aprNU3 djgpp.orig/tests/libc/ansi/stdio/makefile djgpp/tests/libc/ansi/stdio/makefile --- djgpp.orig/tests/libc/ansi/stdio/makefile 2003-11-23 21:14:48 +0000 +++ djgpp/tests/libc/ansi/stdio/makefile 2008-04-24 15:09:08 +0000 @@ -16,6 +16,7 @@ SRC += hello.c SRC += mktemp.c SRC += printf.c SRC += printf2.c +SRC += printf3.c SRC += sscanf.c SRC += sscanf2.c SRC += sscanf3.c diff -aprNU3 djgpp.orig/tests/libc/ansi/stdio/printf3.c djgpp/tests/libc/ansi/stdio/printf3.c --- djgpp.orig/tests/libc/ansi/stdio/printf3.c 1970-01-01 00:00:00 +0000 +++ djgpp/tests/libc/ansi/stdio/printf3.c 2008-04-24 15:09:08 +0000 @@ -0,0 +1,475 @@ +/* + * printf3.c + * Test cases for %a and %A conversion specifiers new to the ANSI C99 standard. + */ + +#include +#include +#include + +#define LOWER_CASE 0 +#define UPPER_CASE 1 + +static const char *to_be_printed[30][2] = { + /* + * Long double test. + * Normalized Finite. + */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 0: No precision given. Exact mantissa representation requested. */ + {"0xf.123456789ab0000p+0", "-0XF.123456789AB0000P+0"}, /* 1: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0xf.000000000000000p+0", "-0XF.000000000000000P+0"}, /* 2: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0xf.123456789fp+0", "-0XF.123456789FP+0"}, /* 3: 9 precision digits. Rounding to even. */ + {"0xf.1234567891p+0", "-0XF.1234567891P+0"}, /* 4: 9 precision digits. Rounding to even. */ + {"0xf.1234567898p+0", "-0XF.1234567898P+0"}, /* 5: 9 precision digits. Rounding to even. */ + {"0xf.123456788p+0", "-0XF.123456788P+0"}, /* 6: 8 precision digits. Rounding to even. */ + {"0xf.f00000000000000p+0", "-0XF.F00000000000000P+0"}, /* 7: 0 precision digits. Rounding to even. */ + {"0xf.100000000000000p+0", "-0XF.100000000000000P+0"}, /* 8: 0 precision digits. Rounding to even. */ + {"0x8.fedcba987654321p+0", "-0X8.FEDCBA987654321P+0"}, /* 9: 0 precision digits. Alternate flag given. */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 10: 6 precision digits and 20 digits of field width. */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 11: 6 precision digits and 20 digits of field width and zero padding. */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 12: 6 precision digits and 20 digits of field width and zero padding and a sign. */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 13: 30 precision digits and 40 digits of field width and zero padding and a sign. */ + + /* + * Long double test. + * Denormalized Finite. + * + * Long doubles as defined by intel's fpu. + * bias: 0x3fff + * Smallest licit exponent: -(bias - 1) = -16382 + * Radix is 2. + * Mantissa of 64 bits with explicit integer bit. Makes possible exact hex representation of mantissa. + * Shifting binary point by 3 places to the right allows to represent the integer part of the mantissa + * with one single hex digit. + */ + {"0x7.fffffffffffffffp-(16382 + 3)", "-0X7.FFFFFFFFFFFFFFFP-(16382 + 3)"}, /* 14: No precision given. Exact mantissa representation requested. */ + {"0x0.123456789abcdefp-(16382 + 3)", "-0X0.123456789ABCDEFP-(16382 + 3)"}, /* 15: No precision given. Exact mantissa representation requested. */ + {"0x0.800000000000000p-(16382 + 3)", "-0X0.800000000000000P-(16382 + 3)"}, /* 16: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0x0.000000012345678p-(16382 + 3)", "-0X0.000000012345678P-(16382 + 3)"}, /* 17: 3 precision digits. Rounding to even. */ + {"0x0.000000012345678p-(16382 + 3)", "-0X0.000000012345678P-(16382 + 3)"}, /* 18: 12 precision digits. Rounding to even. Padding with 0. */ + {"0x0.0000000f1000000p-(16382 + 3)", "-0X0.0000000F1000000P-(16382 + 3)"}, /* 19: 0 precision digits. Rounding to even. */ + {"0x0.0000000ff000000p-(16382 + 3)", "-0X0.0000000FF000000P-(16382 + 3)"}, /* 20: 0 precision digits. Rounding to even. */ + {"0x0.000000080000000p-(16382 + 3)", "-0X0.000000080000000P-(16382 + 3)"}, /* 21: 0 precision digits. Alternate flag given. */ + {"0x0.000000012345678p-(16382 + 3)", "-0X0.000000012345678P-(16382 + 3)"}, /* 22: 6 precision digits and 20 digits of field width. */ + {"0x0.000000012345678p-(16382 + 3)", "-0X0.000000012345678P-(16382 + 3)"}, /* 23: 6 precision digits and 20 digits of field width and zero padding. */ + {"+0x0.000000012345678p-(16382 + 3)", "-0X0.000000012345678P-(16382 + 3)"}, /* 24: 6 precision digits and 20 digits of field width and zero padding and a sign. */ + {"+0x0.123456789abcdefp-(16382 + 3)", "-0X0.123456789ABCDEFP-(16382 + 3)"}, /* 25: 30 precision digits and 50 digits of field width and zero padding and a sign. */ + + /* + * Long double test. + * Zero, INF, NAN and Unnormal. + */ + {"0x0.0p+0", "-0X0.0P+0"}, /* 26: No precision given. Exact mantissa representation requested. */ + {"infinity", "-INFINITY"}, /* 27: No precision given. Exact mantissa representation requested. */ + {"not a number", "NOT A NUMBER"}, /* 28: No precision given. Exact mantissa representation requested. */ + {"Unnormal", "-Unnormal"} /* 29: No precision given. Exact mantissa representation requested. */ +}; + +static const char *should_looks_like[30][2] = { + /* + * Long double test. + * Normalized Finite. + */ + {"0xf.123456789abcdefp+0", "-0XF.123456789ABCDEFP+0"}, /* 0: No precision given. Exact mantissa representation requested. */ + {"0xf.123456789abp+0", "-0XF.123456789ABP+0"}, /* 1: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0xfp+0", "-0XFP+0"}, /* 2: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0xf.12345678ap+0", "-0XF.12345678AP+0"}, /* 3: 9 precision digits. Rounding to even. */ + {"0xf.123456789p+0", "-0XF.123456789P+0"}, /* 4: 9 precision digits. Rounding to even. */ + {"0xf.12345678ap+0", "-0XF.12345678AP+0"}, /* 5: 9 precision digits. Rounding to even. */ + {"0xf.12345678p+0", "-0XF.12345678P+0"}, /* 6: 8 precision digits. Rounding to even. */ + {"0x1p+4", "-0X1P+4"}, /* 7: 0 precision digits. Rounding to even. */ + {"0xfp+0", "-0XFP+0"}, /* 8: 0 precision digits. Rounding to even. */ + {"0x9.p+0", "-0X9.P+0"}, /* 9: 0 precision digits. Alternate flag given. */ + {" 0xf.123456p+0", " -0XF.123456P+0"}, /* 10: 6 precision digits and 20 digits of field width. */ + {"0x0000000f.123456p+0", "-0X000000F.123456P+0"}, /* 11: 6 precision digits and 20 digits of field width and zero padding. */ + {"+0x000000f.123456p+0", "-0X000000F.123456P+0"}, /* 12: 6 precision digits and 20 digits of field width and zero padding and a sign. */ + {"+0x00f.123456789abcdef000000000000000p+0", + "-0X00F.123456789ABCDEF000000000000000P+0"}, /* 13: 30 precision digits and 40 digits of field width and zero padding and a sign. */ + + /* + * Long double test. + * Denormalized Finite. + */ + {"0x7.fffffffffffffffp-16385", "-0X7.FFFFFFFFFFFFFFFP-16385"}, /* 14: No precision given. Exact mantissa representation requested. */ + {"0x1.23456789abcdefp-16389", "-0X1.23456789ABCDEFP-16389"}, /* 15: No precision given. Exact mantissa representation requested. */ + {"0x8p-16389", "-0X8P-16389"}, /* 16: No precision given. Exact mantissa representation requested. Trailing zeros will be omitted. */ + {"0x1.234p-16417", "-0X1.234P-16417"}, /* 17: 3 precision digits. Rounding to even. */ + {"0x1.234567800000p-16417", "-0X1.234567800000P-16417"}, /* 18: 12 precision digits. Rounding to even. Padding with 0. */ + {"0xfp-16417", "-0XFP-16417"}, /* 19: 0 precision digits. Rounding to even. */ + {"0x1p-16413", "-0X1P-16413"}, /* 20: 0 precision digits. Rounding to even. */ + {"0x8.p-16417", "-0X8.P-16417"}, /* 21: 0 precision digits. Alternate flag given. */ + {" 0x1.234568p-16417", " -0X1.234568P-16417"}, /* 22: 6 precision digits and 20 digits of field width. */ + {"0x0001.234568p-16417", "-0X001.234568P-16417"}, /* 23: 6 precision digits and 20 digits of field width and zero padding. */ + {"+0x001.234568p-16417", "-0X001.234568P-16417"}, /* 24: 6 precision digits and 20 digits of field width and zero padding and a sign. */ + {"+0x000000001.23456789abcdef0000000000000000p-16389", + "-0X000000001.23456789ABCDEF0000000000000000P-16389"}, /* 25: 30 precision digits and 50 digits of field width and zero padding and a sign. */ + + /* + * Long double test. + * Zero, INF, NAN and Unnormal. + */ + {"0x0p+0", "-0X0P+0"}, /* 26: No precision given. Exact mantissa representation requested. */ + {"inf", "-INF"}, /* 27: No precision given. Exact mantissa representation requested. */ + {"nan", "-NAN"}, /* 28: No precision given. Exact mantissa representation requested. */ + {"nan", "-NAN"}, /* 29: No precision given. Exact mantissa representation requested. */ +}; + +static long_double_t number[] = { +/* mantissal mantissah exp sgn */ + {0x89ABCDEFU, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 0: 0xF.123456789ABCDEFp+0 */ + {0x89AB0000U, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 1: 0xF.123456700000000p+0 */ + {0x00000000U, 0xF0000000U, 0x3FFFU + 0x03U, 0x0U}, /* 2: 0xF.000000000000000p+0 */ + {0x89F00000U, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 3: 0xF.123456789Fp+0 */ + {0x89100000U, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 4: 0xF.1234567891p+0 */ + {0x89800000U, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 5: 0xF.1234567898p+0 */ + {0x88000000U, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 6: 0xF.123456788p+0 */ + {0x00000000U, 0xFF000000U, 0x3FFFU + 0x03U, 0x0U}, /* 7: 0xF.F00000000000000p+0 */ + {0x00000000U, 0xF1000000U, 0x3FFFU + 0x03U, 0x0U}, /* 8: 0xF.F00000000000000p+0 */ + {0x87654321U, 0x8FEDCBA9U, 0x3FFFU + 0x03U, 0x0U}, /* 9: 0x8.FEDCBA987654321p+0 */ + {0x89ABCDEFU, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 10: 0xF.123456789ABCDEFp+0 */ + {0x89ABCDEFU, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 11: 0xF.123456789ABCDEFp+0 */ + {0x89ABCDEFU, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 12: 0xF.123456789ABCDEFp+0 */ + {0x89ABCDEFU, 0xF1234567U, 0x3FFFU + 0x03U, 0x0U}, /* 13: 0xF.123456789ABCDEFp+0 */ + + {0xFFFFFFFFU, 0x7FFFFFFFU, 0x0000U, 0x0U}, /* 14: 0x7.FFFFFFFFFFFFFFFp-16385 */ + {0x89ABCDEFU, 0x01234567U, 0x0000U, 0x0U}, /* 15: 0x0.123456789ABCDEFp-16385 */ + {0x00000000U, 0x08000000U, 0x0000U, 0x0U}, /* 16: 0x0.800000000000000p-16385 */ + {0x12345678U, 0x00000000U, 0x0000U, 0x0U}, /* 17: 0x0.000000012345678p-16385 */ + {0x12345678U, 0x00000000U, 0x0000U, 0x0U}, /* 18: 0x0.000000012345678p-16385 */ + {0xF1000000U, 0x00000000U, 0x0000U, 0x0U}, /* 19: 0x0.0000000F1000000p-16385 */ + {0xFF000000U, 0x00000000U, 0x0000U, 0x0U}, /* 20: 0x0.0000000FF000000p-16385 */ + {0x80000000U, 0x00000000U, 0x0000U, 0x0U}, /* 21: 0x0.000000080000000p-16385 */ + {0x12345678U, 0x00000000U, 0x0000U, 0x0U}, /* 22: 0x0.000000012345678p-16385 */ + {0x12345678U, 0x00000000U, 0x0000U, 0x0U}, /* 23: 0x0.000000012345678p-16385 */ + {0x12345678U, 0x00000000U, 0x0000U, 0x0U}, /* 24: 0x0.000000012345678p-16385 */ + {0x89ABCDEFU, 0x01234567U, 0x0000U, 0x0U}, /* 25: 0x0.123456789ABCDEFp-16385 */ + + {0x00000000U, 0x00000000U, 0x0000U, 0x0U}, /* 26: 0x0.000000000000000p+0 */ + {0x00000000U, 0x80000000U, 0x7FFFU, 0x0U}, /* 27: INFINITY */ + {0x00000000U, 0xC0000000U, 0x7FFFU, 0x0U}, /* 28: NAN */ + {0x00000000U, 0x00000000U, 0x7FFFU, 0x0U}, /* 29: Unnormal */ +}; + + + +int +main (void) +{ + _longdouble_union_t value; + unsigned int i = 0; + + printf("Testing normalized finite numbers.\n"); + printf("Printing value without specifying a precision. Mantissa representation shall be exact.\n"); + printf("Test: %u\n", i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value without specifying a precision.\nMantissa representation shall be exact.\nTrailing zeros will always be omitted.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 9 digits of precision. Rounding to even.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.9La: %.9La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.9LA: %.9LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.9La: %.9La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.9LA: %.9LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.9La: %.9La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.9LA: %.9LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 8 digits of precision. Rounding to even.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.8La: %.8La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.8LA: %.8LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 0 digits of precision. Rounding to even.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.0La: %.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.0LA: %.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.0La: %.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.0LA: %.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 0 digits of precision and alternate flag given.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%#.0La: %#.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%#.0LA: %#.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%20.6La: %20.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%20.6LA: %20.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits and zero padding.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%020.6La: %020.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%020.6LA: %020.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits and zero padding and a sign.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%+020.6La: %+020.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%+020.6LA: %+020.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 30 digits of precision and field width of 40 digits and zero padding and a sign.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%+040.30La: %+040.30La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%+040.30LA: %+040.30LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + + + printf("\n\nTesting denormalized finite numbers. Smallest exponent: -16382.\nTo get a single nibble in the integer part of the mantissa\nthe exponent must be incremented by 3.\n"); + printf("Printing value without specifying a precision. Mantissa representation shall be exact.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value without specifying a precision. Mantissa representation shall be exact.\nTrailing zeros will always be omitted.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 3 digits of precision. Rounding to even.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.3La: %.3La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.3LA: %.3LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 12 digits of precision. Rounding to even.\nPadding with 0 if precision is greater than number of significant digits in the mantissa.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.12La: %.12La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.12LA: %.12LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 0 digits of precision. Rounding to even.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.0La: %.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.0LA: %.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%.0La: %.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%.0LA: %.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 0 digits of precision and alternate flag given.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%#.0La: %#.0La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%#.0LA: %#.0LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%20.6La: %20.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%20.6LA: %20.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits and zero padding.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%020.6La: %020.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%020.6LA: %020.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 6 digits of precision and field width of 20 digits and zero padding and a sign.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%+020.6La: %+020.6La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%+020.6LA: %+020.6LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + printf("\nPrinting value with 30 digits of precision and field width of 50 digits and zero padding and a sign.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%+050.30La: %+050.30La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%+050.30LA: %+050.30LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + + + printf("\n\nTesting 0.0, NAN, INF and Unnormal.\n"); + printf("Printing value without specifying a precision.\n"); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + printf("Test: %u\n", ++i); + value.ldt = number[i]; + printf("value to be printed: %s\n" + "value printed with %%La: %La\n" + "should be: %s\n\n", to_be_printed[i][LOWER_CASE], value.ld, should_looks_like[i][LOWER_CASE]); + printf("value to be printed: %s\n" + "value printed with %%LA: %LA\n" + "should be: %s\n\n", to_be_printed[i][UPPER_CASE], -value.ld, should_looks_like[i][UPPER_CASE]); + + + return(EXIT_SUCCESS); +}