Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf: Fix printf 'mixed_format_random' #2236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lakshmih
Copy link

%a or %A with printf on MSVC platforms have a default precision of 13, which is in contrast to OpenCL C specification for printf which only allows for exact digits required if precision is not specified.

%a or %A with printf on MSVC platforms have a default precision
of 13, which is in contrast to OpenCL C specification for printf
which only allows for exact digits required if precision is not
specified.
@lakshmih
Copy link
Author

https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#printf – OpenCL C Spec

a,A A double, halfn, floatn or doublen argument representing a floating-point number is converted in the style [-]0xh.hhhh p±d, where there is one hexadecimal digit (which is nonzero if the argument is a normalized floating-point number and is otherwise unspecified) before the decimal-point character [[77](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#_footnotedef_77)] and the number of hexadecimal digits after it is equal to the precision; if the precision is missing, then the precision is sufficient for an exact representation of the value; if the precision is zero and the # flag is not specified, no decimal point character appears. The letters abcdef are used for a conversion and the letters ABCDEF for A conversion. The A conversion specifier produces a number with X and P instead of x and p. The exponent always contains at least one digit, and only as many more digits as necessary to represent the decimal exponent of 2. If the value is zero, the exponent is zero. A double, halfn, floatn or doublen argument representing an infinity or NaN is converted in the style of an f or F conversion specifier.

https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-170#precision – Microsoft

a, A | The precision specifies the number of digits after the point. | Default precision is 13. If precision is 0, no decimal point is printed unless the # flag is used.

https://man.openbsd.org/printf - OpenBSD
The argument is printed in style [-]0xh.hhhp[±]d where there is one digit before the hexadecimal point and the number after is equal to the precision specification for the argument. When the precision is missing, enough digits are produced to convey the argument's exact double-precision floating-point representation.

@bashbaug
Copy link
Contributor

Discussed in the January 21st teleconference. As a short term fix could we add an explicit precision for %a? This will buy us some time to figure out how to test %a without an explicit precision and is consistent with other similar "fixes" (e.g. #2064).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants