Float16 default argument promotions

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Float16 default argument promotions

Adam Cieszkiel via cfe-dev

Hi,

 

I am implementing support for the C11  _Float16 type, see [1], as defined in ISO/IEC TS 18661 and have a question about default argument promotions for variadic functions.

 

For the *decimal* floating types the behaviour is well specified as section “9.5 Default argument promotion” in [2] reads:

“There is no default argument promotion specified for the decimal floating types. Default argument promotion

covered in C11 6.5.2.2 [6] and [7] remains unchanged, and applies to standard floating types only.”

 

But for the *binary* floating types such a paragraph is absent by N1774, see [3], so the question is if default argument promotion should apply here? Another way of looking at TS 18661 is as a set of changes to the C11 specification, in which case absence of an edit to 6.5.2.2 would mean that the current text still applies, i.e. only float is promoted to double, which is the approach GCC has taken: “In TS 18661-3, _Float16 is *not* affected by default argument promotions; only float is.”, see e.g. this message on the GCC list [4].

 

First of all, I don’t quite understand why the binary floating type spec does not mention default argument promotion, but secondly and more importantly, how does e.g. printf works now? Default argument promotion to double would actually be really convenient/user-friendly because printf(“%f”) would just work, which is currently broken. Assuming that default argument promotion does not apply, I am expecting the spec to say something about string format specifier for _Float16 types, but haven’t found anything (if I didn’t miss anything).

 

One workaround is to document that explicit casts are required, e.g. printf(“%f”,  (double)MyFloat16), but this of course not ideal. Another one is to create a specifier for Float16, or let e.g. some length modifier apply to “f”. But perhaps default argument promotion for variadic functions wouldn’t be so bad after all? I was wondering if anyone has some thoughts on this?

 

[1] https://reviews.llvm.org/D33719

[2] http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1912.pdf

[3] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1774.pdf

[4] https://gcc.gnu.org/ml/gcc-patches/2016-04/msg01858.html

 

Cheers,

Sjoerd.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...