Repository navigation
Cast a real to numeric with six significant digits, as PostgreSQL - #3001
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #2492.
PostgreSQL casts a
realtonumericthrough its text with 6 significant digits (float4_numericprints withFLT_DIG), and adouble precisionwith 15 (DBL_DIG). rudb widened arealto a double and printed it with 15 digits, so16777216::float4::numericgave16777216and(1.0/3.0)::float4::numericgave0.333333343267441. PostgreSQL gives16777200and0.333333.Numeric::from_f32now prints the float with 6 significant digits, andNumeric::from_f64and it share the code that reads the digits back. The PostgreSQLnumericcast inrudb-kernelscalls the one that matches the type of the value. The pin has nonumerictype, so this does not change it.A unit test in
rudb-pgtypeschecks 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 forstddev,var_samp,sumandavgoverb::numericwherebis areal. On the harness the statements score goes from 1862 to 1866 of 2588 (all four in aggregates), and nothing regresses.