You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "vtlim (via GitHub)" <gi...@apache.org> on 2023/03/15 16:38:32 UTC

[GitHub] [druid] vtlim commented on a diff in pull request #13671: docs: clarify Java precision

vtlim commented on code in PR #13671:
URL: https://github.com/apache/druid/pull/13671#discussion_r1137418720


##########
docs/querying/sql-operators.md:
##########
@@ -37,6 +37,13 @@ sidebar_label: "Operators"
 
 Operators in [Druid SQL](./sql.md) typically operate on one or two values and return a result based on the values. Types of operators in Druid SQL include arithmetic, comparison, logical, and more, as described here. 
 
+When performing math operations, Druid uses 64-bit integer (long) data type unless there are double or float values. If an operation uses float or double values, then the result is a double, which is a 64-bit float. The precision of float and double values is defined by [Java](https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html) and [the IEEE standard](https://en.wikipedia.org/wiki/IEEE_754).
+
+Keep the following guidelines in mind to help you manage precision issues:
+
+- Long values can store up to 2^63 accurately with an additional bit used for the sign.
+- Float values use 32 bits, and doubles use 64-bits. Both types are impacted by floating point precision. If you need exact decimal values, consider storing the number in a non-decimal format as a long value (up to the limit for longs). For example, if you need three decimal places, store the number multiplied by 1000 and then divide by 1000 when querying.

Review Comment:
   Stay consistent with hyphen usageI



##########
docs/querying/sql-operators.md:
##########
@@ -37,6 +37,13 @@ sidebar_label: "Operators"
 
 Operators in [Druid SQL](./sql.md) typically operate on one or two values and return a result based on the values. Types of operators in Druid SQL include arithmetic, comparison, logical, and more, as described here. 
 
+When performing math operations, Druid uses 64-bit integer (long) data type unless there are double or float values. If an operation uses float or double values, then the result is a double, which is a 64-bit float. The precision of float and double values is defined by [Java](https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html) and [the IEEE standard](https://en.wikipedia.org/wiki/IEEE_754).
+
+Keep the following guidelines in mind to help you manage precision issues:
+
+- Long values can store up to 2^63 accurately with an additional bit used for the sign.
+- Float values use 32 bits, and doubles use 64-bits. Both types are impacted by floating point precision. If you need exact decimal values, consider storing the number in a non-decimal format as a long value (up to the limit for longs). For example, if you need three decimal places, store the number multiplied by 1000 and then divide by 1000 when querying.

Review Comment:
   Stay consistent with hyphen usage



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org