[Cfp-interest] Fwd: outstanding issues

Jim Thomas jaswthomas at sbcglobal.net
Thu Apr 19 07:56:47 PDT 2012


A spec for the the approach below might look something like this:

After 7.22.1.2, add:
 
7.22.1.3   The strfromflt function

Synopsis

#define __STDC_WANT_IEC_60559_BFP__
#include <stdlib.h>
int strfromflt(char * restrict s, size_t n, const char * restrict format, …);
 
Descripton
 
The strfromflt function is equivalent to snprintf (7.21.6.5) except the format string shall contain at most one conversion specifier, which, if present, shall be e, E, f, F, g, G, a, or A, with an optional l or L length modifier. Use of other format strings results in undefined behavior. [footnote]
 
Returns
 
The strfromflt function returns the values returned by snprintf (7.21.6.5), for valid input.
 
[footnote] strfromflt may be equivalent to snprintf.

-Jim


Begin forwarded message:

> From: Jim Thomas <jaswthomas at sbcglobal.net>
> Subject: Re: [Cfp-interest] outstanding issues
> Date: April 11, 2012 10:57:41 AM PDT
> To: CFP <cfp-interest at ucbtest.org>
> 
> This looks like an approach to consider. Freestanding implementations already need to support ellipsis notation. Instead of the 'Q' modifier we could have an optional 'L', which would cover all the standard floating types. 
> 
> -Jim
> 
> On Apr 11, 2012, at 10:23 AM, Fred J. Tydeman wrote:
> 
>> On Tue, 10 Apr 2012 16:35:30 -0700 Jim Thomas wrote:
>>> 
>>> ISSUE 3: Would it be better to restrict the format specifiers 
>>> that the strfrom functions have to support?
>> 
>> 
>> I recently discovered that gcc has similar support.
>>> From the info pages on libquadmath:
>> 
>> 3.2 `quadmath_snprintf' -- Convert to string
>> ============================================
>> 
>> The function `quadmath_snprintf' converts a `__float128' floating-point
>> number into a string.  It is a specialized alternative to `snprintf',
>> where the format string is restricted to a single conversion specifier
>> with `Q' modifier and conversion specifier `e', `E', `f', `F', `g',
>> `G', `a' or `A', with no extra characters before or after the
>> conversion specifier.  The `%m$' or `*m$' style must not be used in the
>> format.
>> 
>> Syntax
>>    `int quadmath_snprintf (char *s, size_t size, const char *format,
>>    ...)'
>> 
>> _Arguments_:
>>    S          output string
>>    SIZE       byte size of the string, including tailing NUL
>>    FORMAT     conversion specifier string
>> 
>> Example
>>         #include <quadmath.h>
>>         #include <stdlib.h>
>>         #include <stdio.h>
>> 
>>         int main ()
>>         {
>>           __float128 r;
>>           int prec = 20;
>>           int width = 46;
>>           char buf[128];
>> 
>>           r = 2.0q;
>>           r = sqrtq (r);
>>           int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, r);
>>           if ((size_t) n < sizeof buf)
>>             printf ("%s\n", buf);
>>             /* Prints: +1.41421356237309504880e+00 */
>>           quadmath_snprintf (buf, sizeof buf, "%Qa", r);
>>           if ((size_t) n < sizeof buf)
>>             printf ("%s\n", buf);
>>             /* Prints: 0x1.6a09e667f3bcc908b2fb1366ea96p+0 */
>>           n = quadmath_snprintf (NULL, 0, "%+-#46.*Qe", prec, r);
>>           if (n > -1)
>>             {
>>               char *str = malloc (n + 1);
>>               if (str)
>>                 {
>>                   quadmath_snprintf (str, n + 1, "%+-#46.*Qe", prec, r);
>>                   printf ("%s\n", str);
>>                   /* Prints: +1.41421356237309504880e+00 */
>>                 }
>>               free (str);
>>             }
>>           return 0;
>>         }
>> 
>> 
>>  On some targets when supported by the C library hooks are installed
>> for `printf' family of functions, so that `printf ("%Qe", 1.2Q);' etc.
>> works too.
>> 
>> 
>> 
>> 
>> 
>> ---
>> Fred J. Tydeman        Tydeman Consulting
>> tydeman at tybor.com      Testing, numerics, programming
>> +1 (775) 358-9748      Vice-chair of PL22.11 (ANSI "C")
>> Sample C99+FPCE tests: http://www.tybor.com
>> Savers sleep well, investors eat well, spenders work forever.
>> 
>> _______________________________________________
>> Cfp-interest mailing list
>> Cfp-interest at oakapple.net
>> http://mailman.oakapple.net/mailman/listinfo/cfp-interest
> 
> 
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20120419/dc3ab27e/attachment.html 


More information about the Cfp-interest mailing list