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] half-even rounding gives 0 instead of ±1 when the truncated quotient is 0 · Issue #7717 · feldera/feldera

[fxp] half-even rounding gives 0 instead of ±1 when the truncated quotient is 0 #7717

New issue
Copy link
New issue
Copy link
Closed
Bug
#7796
Closed
[fxp] half-even rounding gives 0 instead of ±1 when the truncated quotient is 0#7717
Bug
#7796
Copy link
Assignees
blp

Description

@ryzhyk
ryzhyk
opened on Oct 29, 2026
Issue body actions

i128_mul_pow10_round_even (crates/fxp/src/lib.rs) rounds away from zero with quotient + quotient.signum(). When the truncated quotient is 0, its signum is 0, so a value that should round to ±1 comes out 0: 0.6 at scale 0 gives 0, not 1. Ties are unaffected (0.5 gives 0, as half-even should), and so is any value with a nonzero quotient (1.6 gives 2).

Every half-even path in fxp goes through this function: Fixed::from_str, Fixed::convert_round_even, Fixed::new_round_even and DynamicDecimal::into_fixed_round_even.

SQL effect:

CREATE TABLE t (s VARCHAR, d DECIMAL(10, 4));
CREATE VIEW v AS SELECT CAST(s AS DECIMAL(5, 0)) AS a, CAST(d AS TIMESTAMP) AS b FROM t;
-- With the row ('0.6', 0.0006) in t:
--   a = 0, expected 1 (cast_to_SqlDecimal_s parses with Fixed::from_str)
--   b = 1970-01-01 00:00:00, expected 1970-01-01 00:00:00.000001
--       (cast_to_Timestamp_SqlDecimal rescales with convert_round_even::<38, 3>)

Repro in fxp alone; each assert fails on main 462ef2e, and the comment shows the actual value:

assert_eq!(Fixed::<5, 0>::from_str("0.6").unwrap().to_string(), "1");    // "0"
assert_eq!(Fixed::<5, 0>::from_str("-0.6").unwrap().to_string(), "-1");  // "0"
assert_eq!(Fixed::<5, 1>::from_str("0.06").unwrap().to_string(), "0.1"); // "0"
let ms = Fixed::<10, 4>::from_str("0.0006").unwrap();
assert_eq!(ms.convert_round_even::<38, 3>().unwrap().to_string(), "0.001"); // "0"

Fix: step by the sign of the value instead of the quotient: quotient + value.signum().

Activity

  1. ryzhyk
    assigned
    blp
    on Oct 29, 2026
  2. ryzhyk
    added the
    Bug
    issue type on Oct 29, 2026
  3. blp
    added a commit that references this issue on Nov 3, 2026

    [fxp] Round half-even values below one unit to ±1, not 0.

    This issue will close once commit 7f9fee6 is merged into the 'main' branch.
    7f9fee6
  4. blp
    closed this as completedin #7796on Nov 3, 2026
  5. AnnaZhand
    added a commit that references this issue on Nov 3, 2026

    [fxp] Round half-even values below one unit to ±1, not 0.

    This issue will close once commit c9ce238 is merged into the 'main' branch.
    c9ce238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @blp
    blp

Labels

No labels
No labels

Type

Bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.