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

Jim Thomas jaswthomas at sbcglobal.net
Sat Jul 25 15:18:26 PDT 2020


I’d like to avoid alluding to the size of a string. It’s really a size greater than the lengths of the hex strings, which is what is needed for the array size. The C standard uses “maxsize” for parameters with this meaning. How about 

#define MAXSIZE 41	// > intermediate hex string length

- Jim Thomas

> On Jul 24, 2020, at 6:36 AM, Mike Cowlishaw <mfc at speleotrove.com> wrote:
> 
> 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/20200725/b039fea6/attachment-0001.htm>


More information about the Cfp-interest mailing list