AMashenkov commented on code in PR #2396:
URL: https://github.com/apache/ignite-3/pull/2396#discussion_r1285838232
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -246,7 +234,86 @@ public static BigDecimal convertDecimal(BigDecimal value,
int precision, int sca
}
}
- return value.setScale(scale, RoundingMode.HALF_UP);
+ return dec.setScale(scale, RoundingMode.HALF_UP);
+ }
+
+ /** Check precision scale for fraction numbers. */
+ private static boolean checkPrecisionScaleFractionPart(Number num, int
precision, int scale) {
+ if (num.longValue() != 0) {
+ return false;
+ }
+
+ if (!(num instanceof Double) && !(num instanceof Float) && !(num
instanceof BigDecimal)) {
+ return false;
+ }
+
+ boolean canProcess = true;
+
+ if (num instanceof Double) {
+ Double num0 = (Double) num;
+ canProcess = !num0.isInfinite() && !num0.isNaN();
+ }
+
+ if (num instanceof Float) {
+ Float num0 = (Float) num;
+ canProcess = !num0.isInfinite() && !num0.isNaN();
+ }
+
+ if (canProcess) {
+ int lastSignificantDigit = 0;
+
+ String strRepr = num.toString();
+ int pos = strRepr.indexOf('.');
+
+ if (pos == -1) {
+ return false;
+ }
+
+ // fractional part
+ strRepr = strRepr.substring(pos + 1);
+
+ // length of fractional part
+ int processingDigits = strRepr.length();
+
+ // cut if scale is less than processing digits
+ if (scale < processingDigits) {
+ strRepr = strRepr.substring(0, scale);
+ }
+
+ // calculate overall processing digits
+ int digit = scale > processingDigits ? scale - processingDigits :
0;
+ for (int i = strRepr.length() - 1; i >= 0; i--) {
+ digit++;
+ if (strRepr.charAt(i) != '0') {
+ lastSignificantDigit = digit;
+ }
+ }
+
+ if (lastSignificantDigit > precision) {
Review Comment:
Does `lastSignificant` value equals to BigDeciman.ulp().scale() ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]