GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fxp] Round half-even values below one unit to ±1, not 0. · feldera/feldera@c9ce238

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/fxp/src
    • fixed.rs
    • lib.rs
  • sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple
    • CastTests.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/fxp/src/fixed.rs‎

Copy file name to clipboardExpand all lines: crates/fxp/src/fixed.rs
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,34 @@ mod test {
17991799
assert_eq!(b.convert_round_even::<10, 10>(), None);
18001800
}
18011801

1802+
/// Half-even rounding of a value with magnitude below one unit of the
1803+
/// target scale (https://github.com/feldera/feldera/issues/7717).
1804+
#[test]
1805+
fn round_even_below_one() {
1806+
let s = |x: Fixed<5, 0>| x.to_string();
1807+
assert_eq!(s(Fixed::from_str("0.6").unwrap()), "1");
1808+
assert_eq!(s(Fixed::from_str("-0.6").unwrap()), "-1");
1809+
assert_eq!(s(Fixed::from_str("0.5").unwrap()), "0");
1810+
assert_eq!(s(Fixed::from_str("-0.5").unwrap()), "0");
1811+
assert_eq!(s(Fixed::from_str("0.4").unwrap()), "0");
1812+
assert_eq!(s(Fixed::from_str("1.6").unwrap()), "2");
1813+
assert_eq!(Fixed::<5, 1>::from_str("0.06").unwrap().to_string(), "0.1");
1814+
1815+
let ms = Fixed::<10, 4>::from_str("0.0006").unwrap();
1816+
assert_eq!(
1817+
ms.convert_round_even::<38, 3>().unwrap().to_string(),
1818+
"0.001"
1819+
);
1820+
let ms = Fixed::<10, 4>::from_str("-0.0006").unwrap();
1821+
assert_eq!(
1822+
ms.convert_round_even::<38, 3>().unwrap().to_string(),
1823+
"-0.001"
1824+
);
1825+
1826+
assert_eq!(s(Fixed::new_round_even(6, 1).unwrap()), "1");
1827+
assert_eq!(s(Fixed::new_round_even(-6, 1).unwrap()), "-1");
1828+
}
1829+
18021830
#[test]
18031831
fn constants() {
18041832
assert_eq!(Fixed::<5, 0>::MAX, Fixed::<5, 0>(99999));
Collapse file

‎crates/fxp/src/lib.rs‎

Copy file name to clipboardExpand all lines: crates/fxp/src/lib.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn i128_mul_pow10_round_even(value: i128, exponent: i32) -> Option<i128> {
387387
Ordering::Greater => true,
388388
};
389389
if round_away_from_zero {
390-
quotient + quotient.signum()
390+
quotient + value.signum()
391391
} else {
392392
quotient
393393
}
Collapse file

‎sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/CastTests.java‎

Copy file name to clipboardExpand all lines: sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/CastTests.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,22 @@ public void issue7395() {
952952
0.12345 | 0.12345600000000000000 | 0.10000000149011612000 | 1""");
953953
}
954954

955+
@Test
956+
public void issue7717() {
957+
// Half-even rounding of a value below one unit of the target scale.
958+
// DECIMAL to TIMESTAMP reads the value as milliseconds, so 0.0006 is 0.6 microseconds.
959+
var ccs = this.getCCS("""
960+
CREATE TABLE R(s VARCHAR, d DECIMAL(10, 4));
961+
CREATE VIEW V AS SELECT CAST(s AS DECIMAL(5, 0)) AS a, CAST(d AS TIMESTAMP) AS b FROM R;""");
962+
ccs.step("INSERT INTO R VALUES ('0.6', 0.0006), ('-0.6', -0.0006), ('0.5', 0.0005), ('1.5', 0.0015)", """
963+
a | b | weight
964+
----------------
965+
1 | 1970-01-01 00:00:00.000001 | 1
966+
-1 | 1969-12-31 23:59:59.999999 | 1
967+
0 | 1970-01-01 00:00:00 | 1
968+
2 | 1970-01-01 00:00:00.000002 | 1""");
969+
}
970+
955971
@Test
956972
public void issue6257() {
957973
// Calcite rounds by truncating, so we are tied to that behavior

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.