+// Determine whether a given roundingIncrement should be ignored for formatting
+// based on the current maxFrac value (maximum fraction digits). For example a
+// roundingIncrement of 0.01 should be ignored if maxFrac is 1, but not if maxFrac
+// is 2 or more. Note that roundingIncrements are rounded in significance, so
+// a roundingIncrement of 0.006 is treated like 0.01 for this determination, i.e.
+// it should not be ignored if maxFrac is 2 or more (but a roundingIncrement of
+// 0.005 is treated like 0.001 for significance). This is the reason for the
+// initial doubling below.
+// roundIncr must be non-zero.
+// Apple enhancement per rdar://51452216: Takes pointer to roundIncr; if function
+// returns false, roundIncr will be rounded as necessary given maxFrac value.
+bool PatternStringUtils::ignoreRoundingIncrement(double* roundIncrPtr, int32_t maxFrac) {
+ if (maxFrac < 0) {
+ return false;
+ }
+ int32_t frac = 0;
+ double denom = 20.0;
+ double roundIncr = *roundIncrPtr * 2.0;
+ for (frac = 0; frac <= maxFrac && roundIncr <= 1.0; frac++, roundIncr *= 10.0, denom *= 10.0);
+ if (frac <= maxFrac) {
+ *roundIncrPtr = (double)((int)(roundIncr*10.0))/denom;
+ return false;
+ }
+ return true;
+}
+