[Cfp-interest 1720] Re: AI about macro for array size in example

Mike Cowlishaw mfc at speleotrove.com
Fri Jul 24 06:36:00 PDT 2020


Looks good.   Maybe MAXSTRSIZE?  (S on its own is a bit mysterious, and it's
not clear how to pronounce it).
 
Mike



  _____  

From: Cfp-interest [mailto:cfp-interest-bounces at oakapple.net] On Behalf Of
Jim Thomas
Sent: 24 July 2020 00:33
To: CFP
Subject: [Cfp-interest 1718] AI about macro for array size in example


Action item:

    Jim: For cfp3x-annex-20200706.pdf, Annex X, new example (page 33),
change the magic number 40 (which needs to be verified) to be a macro and
add in a descriptive definition of that macro.

Oops. 41 instead of 40. How does the following look?

- Jim Thomas

+++++++++++++++++++++++++++

[4] EXAMPLE    If the IEC 60559 binary128 format is supported as a
non-arithmetic format, data in binary128 format can be converted to type
_Decimal128 as follows:

#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include <stdlib.h>

#define MAXSSIZE 41     // of intermediate hexadecimal string 

unsigned char b128[16]; // for input binary128 datum

_Decimal128 d128;       // for result

char s[MAXSSIZE];

// store input binary128 datum in array b128

...

strfromencf128(s, MAXSSIZE, “%a”, b128);

d128 = strtod128(s, NULL);

...

Use of “%a” for formatting assures an exact conversion of the value in
binary format to character sequence. The value of that character sequence
will be correctly rounded to _Decimal128, as specified above in this
subclause. The array s for the output of strfromencf128 need have no greater
size than 41, which is the maximum length of strings of the form

[-]0xh.h
hp±d, where there are up to 29 hexadecimal digits h and d has 5
digits

plus 1 for the null character.

+++++++++++++++++++++++++++












-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20200724/92784566/attachment-0001.htm>


More information about the Cfp-interest mailing list