Skip to content

Commit effe447

Browse files
committed
Decimal Vector
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 73d79d7 commit effe447

File tree

3 files changed

+21
-54
lines changed

3 files changed

+21
-54
lines changed

vortex-dtype/src/decimal/max_precision.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
//! Lookup tables for minumum/maximum i256 decimal values for each precision.
5+
//! We cannot perform const computations for i256, so we precompute these values.
6+
47
use crate::i256;
58

69
pub(super) const MAX_DECIMAL256_FOR_EACH_PRECISION: [i256; 77] = [

vortex-dtype/src/decimal/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ macro_rules! impl_decimal {
117117
const DECIMAL_TYPE: DecimalType = DecimalType::$UPPER;
118118

119119
const MAX_PRECISION: u8 = match DecimalType::$UPPER {
120-
DecimalType::I8 => 3,
121-
DecimalType::I16 => 5,
120+
DecimalType::I8 => 2,
121+
DecimalType::I16 => 4,
122122
DecimalType::I32 => 9,
123123
DecimalType::I64 => 18,
124124
DecimalType::I128 => 38,
@@ -131,8 +131,8 @@ macro_rules! impl_decimal {
131131
let mut p = $T::ONE;
132132
let mut i = 0;
133133
while i < Self::MAX_PRECISION as usize {
134-
mins[i] = -((p * 10) - 1);
135-
p = p * (10 as $T);
134+
p = p * 10;
135+
mins[i] = -(p - 1);
136136
i += 1;
137137
}
138138
mins
@@ -143,8 +143,8 @@ macro_rules! impl_decimal {
143143
let mut p = $T::ONE;
144144
let mut i = 0;
145145
while i < Self::MAX_PRECISION as usize {
146-
maxs[i] = (p * 10) - 1;
147-
p = p * (10 as $T);
146+
p = p * 10;
147+
maxs[i] = p - 1;
148148
i += 1;
149149
}
150150
maxs

vortex-vector/src/decimal/macros.rs

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,12 @@
4343
macro_rules! match_each_dvector {
4444
($self:expr, | $vec:ident | $body:block) => {{
4545
match $self {
46-
$crate::DecimalVector::D8(v) => {
47-
let $vec = v;
48-
$body
49-
}
50-
$crate::DecimalVector::D16(v) => {
51-
let $vec = v;
52-
$body
53-
}
54-
$crate::DecimalVector::D32(v) => {
55-
let $vec = v;
56-
$body
57-
}
58-
$crate::DecimalVector::D64(v) => {
59-
let $vec = v;
60-
$body
61-
}
62-
$crate::DecimalVector::D128(v) => {
63-
let $vec = v;
64-
$body
65-
}
66-
$crate::DecimalVector::D256(v) => {
67-
let $vec = v;
68-
$body
69-
}
46+
$crate::DecimalVector::D8($vec) => $body,
47+
$crate::DecimalVector::D16($vec) => $body,
48+
$crate::DecimalVector::D32($vec) => $body,
49+
$crate::DecimalVector::D64($vec) => $body,
50+
$crate::DecimalVector::D128($vec) => $body,
51+
$crate::DecimalVector::D256($vec) => $body,
7052
}
7153
}};
7254
}
@@ -105,30 +87,12 @@ macro_rules! match_each_dvector {
10587
macro_rules! match_each_dvector_mut {
10688
($self:expr, | $vec:ident | $body:block) => {{
10789
match $self {
108-
$crate::DecimalVectorMut::D8(v) => {
109-
let $vec = v;
110-
$body
111-
}
112-
$crate::DecimalVectorMut::D16(v) => {
113-
let $vec = v;
114-
$body
115-
}
116-
$crate::DecimalVectorMut::D32(v) => {
117-
let $vec = v;
118-
$body
119-
}
120-
$crate::DecimalVectorMut::D64(v) => {
121-
let $vec = v;
122-
$body
123-
}
124-
$crate::DecimalVectorMut::D128(v) => {
125-
let $vec = v;
126-
$body
127-
}
128-
$crate::DecimalVectorMut::D256(v) => {
129-
let $vec = v;
130-
$body
131-
}
90+
$crate::DecimalVectorMut::D8($vec) => $body,
91+
$crate::DecimalVectorMut::D16($vec) => $body,
92+
$crate::DecimalVectorMut::D32($vec) => $body,
93+
$crate::DecimalVectorMut::D64($vec) => $body,
94+
$crate::DecimalVectorMut::D128($vec) => $body,
95+
$crate::DecimalVectorMut::D256($vec) => $body,
13296
}
13397
}};
13498
}

0 commit comments

Comments
 (0)