[Cfp-interest 1718] AI about macro for array size in example

Jim Thomas jaswthomas at sbcglobal.net
Thu Jul 23 16:32:34 PDT 2020


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/20200723/5a4cff15/attachment-0001.htm>


More information about the Cfp-interest mailing list