MCPcopy Create free account
hub / github.com/questdb/questdb / Decimal64

Class Decimal64

core/src/main/java/io/questdb/std/Decimal64.java:26–970  ·  view source on GitHub ↗

Decimal64 - a mutable decimal number implementation using 64-bit arithmetic. The value is a signed number with two's complement representation. This class represents decimal numbers with a fixed scale (number of decimal places) using 64-bit integer arithmetic for precise calculations. All operat

Source from the content-addressed store, hash-verified

24 * </p>
25 */
26public class Decimal64 implements Sinkable, Decimal {
27 public static final int MAX_PRECISION = 18;
28 /**
29 * Maximum allowed scale (number of decimal places)
30 * Limited by the range of 64-bit signed long
31 */
32 public static final int MAX_SCALE = 18;
33 public static final Decimal64 MAX_VALUE = new Decimal64(999999999999999999L, 0);
34 public static final Decimal64 MIN_VALUE = new Decimal64(-999999999999999999L, 0);
35 public static final Decimal64 NULL_VALUE = new Decimal64(Decimals.DECIMAL64_NULL, 0);
36 public static final Decimal64 ONE = new Decimal64(1, 0);
37 public static final Decimal64 ZERO = new Decimal64(0, 0);
38 // Maximum values that 10^n can multiply without overflow
39 private static final long[] MAX_SAFE_MULTIPLY = {
40 999999999999999999L,
41 99999999999999999L,
42 9999999999999999L,
43 999999999999999L,
44 99999999999999L,
45 9999999999999L,
46 999999999999L,
47 99999999999L,
48 9999999999L,
49 999999999L,
50 99999999L,
51 9999999L,
52 999999L,
53 99999L,
54 9999L,
55 999L,
56 99L,
57 9L,
58 0L
59 };
60 // Power of 10 lookup table for 64-bit arithmetic (10^0 to 10^18)
61 private static final long[] TEN_POWERS_TABLE = {
62 1L, // 10^0
63 10L, // 10^1
64 100L, // 10^2
65 1000L, // 10^3
66 10000L, // 10^4
67 100000L, // 10^5
68 1000000L, // 10^6
69 10000000L, // 10^7
70 100000000L, // 10^8
71 1000000000L, // 10^9
72 10000000000L, // 10^10
73 100000000000L, // 10^11
74 1000000000000L, // 10^12
75 10000000000000L, // 10^13
76 100000000000000L, // 10^14
77 1000000000000000L, // 10^15
78 10000000000000000L, // 10^16
79 100000000000000000L, // 10^17
80 1000000000000000000L, // 10^18
81 };
82 private int scale; // Number of decimal places
83 private long value; // The decimal value as an unscaled long

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…