Skip to content

Cast a real to numeric with six significant digits, as PostgreSQL - #3001

Merged
tamnd merged 1 commit into
mainfrom
pg4-float-numeric
Oct 10, 2026
Merged

tamnd merged 1 commit into
mainfrom
pg4-float-numeric

Conversation

@tamnd

@tamnd tamnd commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Part of #2492.

PostgreSQL casts a real to numeric through its text with 6 significant digits (float4_numeric prints with FLT_DIG), and a double precision with 15 (DBL_DIG). rudb widened a real to a double and printed it with 15 digits, so 16777216::float4::numeric gave 16777216 and (1.0/3.0)::float4::numeric gave 0.333333343267441. PostgreSQL gives 16777200 and 0.333333.

Numeric::from_f32 now prints the float with 6 significant digits, and Numeric::from_f64 and it share the code that reads the digits back. The PostgreSQL numeric cast in rudb-kernels calls the one that matches the type of the value. The pin has no numeric type, so this does not change it.

A unit test in rudb-pgtypes checks the oracle answers for large, small, negative zero, rounded and infinite values. The scratch server gives the same answers as the PostgreSQL 19 oracle for the casts, and for stddev, var_samp, sum and avg over b::numeric where b is a real. On the harness the statements score goes from 1862 to 1866 of 2588 (all four in aggregates), and nothing regresses.

@tamnd tamnd added kind/bug It does the wrong thing. area/postgres-compat The PostgreSQL wire protocol, server, catalog, dialect and clients. labels Oct 10, 2026
@tamnd
tamnd merged commit a9385db into main Oct 10, 2026
1 check failed
@tamnd
tamnd deleted the pg4-float-numeric branch October 10, 2026 04:14
@tamnd tamnd mentioned this pull request Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/postgres-compat The PostgreSQL wire protocol, server, catalog, dialect and clients. kind/bug It does the wrong thing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant