Open rmartinsanta opened 2 years ago
The bug seems to a discrepancy of the meaning of the '#' symbol in Java and C, relevant parts in bold.
'g' '\u0067' Requires the output to be formatted in general scientific notation as described below. The localization algorithm is applied. After rounding for the precision, the formatting of the resulting magnitude m depends on its value. If m is greater than or equal to 10-4 but less than 10precision then it is represented in decimal format. If m is less than 10-4 or greater than or equal to 10precision, then it is represented in computerized scientific notation. The total number of significant digits in m is equal to the precision. If the precision is not specified, then the default value is 6. If the precision is 0, then it is taken to be 1. If the '#' flag is given then an FormatFlagsConversionMismatchException will be thrown.
Source: https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html
The character % is followed by zero or more of the following flags: The value should be converted to an "alternate form". For o conversions, the first character of the output string is made zero (by prefixing a 0 if it was not zero already). For x and X conversions, a nonzero result has the string "0x" (or "0X" for X conversions) prepended to it. For a, A, e, E, f, F, g, and G conversions, the result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). For g and G conversions, trailing zeros are not removed from the result as they would otherwise be. For other conversions, the result is undefined.
Hi @rmartinsanta, thank you for the precise description. We will look into this issue.
Unfortunately, these kinds of incompatibilities with standard R (GNU-R) are inevitable. In this case, it is just the difference between the standard formatter in Java and in C, but in some cases, GNU-R has corner cases that does not comply to any standard, e.g., GNU-R has its own regular expression engine that handles some cases in a way different from all other standard engines (see this PR https://github.com/r-lib/testthat/pull/1377)
While debugging a possible bug in one R library, found a potential issue in the sprintf function. The formatter seems to not be a valid in Java, while being valid in R.
Minimum code to reproduce that works on standard R:
Result in GraalVM:
Result in R:
Include the folloing info
fastr_errors_pid{xyz}.log
orfastr_errors.log
, attach them to the issue.Frame(d=1): sprintf (called as: sprintf("%#15.10g", 2870)) Frame(d=0): (called as: )