Welcome to thatlinuxbox.com Sunday, December 22 2024 @ 03:26 AM UTC
Floating Point and Decimal Numeric Types
- Monday, January 10 2022 @ 05:35 PM UTC
- Contributed by: Dan Stoner
- Views: 881
Different programming languages and data storage engines use different names for IEEE 754 double-precision floating point (aka "approximate") numbers:
Language / Engine | IEEE 754 double-precision data type name |
---|---|
SQL (Strict Standard) | DOUBLE PRECISION |
PostgreSQL | double precision or float8 or float |
Avro | double |
Python | float or sqlalchemy.Float |
Java | Double |
Perl | Floats are platform dependent (double precision on 64-bit x86) |
C | double |
Go | float64 |
Rust | f64 |
Fixed precision Decimal types are often but not always provided by the stdlib:
Language | Fixed precision / decimal data type name |
---|---|
SQL (Strict Standard) | NUMERIC |
PostgreSQL | numeric |
Avro | NA |
Python | Decimal |
Java | BigDecimal |
Perl | Math::BigFloat (library) |
C | NA |
Go | decimal (via github.com/shopspring/decimal library) |
Rust | Decimal (via rust_decimal library) |
Floating point naming mahem:
The SQL Standard (SQL-99) defines the following approximate numeric data types:
- FLOAT specifies the data type approximate numeric, with binary precision equal to or greater than the value of the specified _precision_. The maximum value of _precision_ is implementation-defined. _precision_ shall not be greater than this value.
- REAL specifies the data type approximate numeric, with implementation-defined _precision_.
- DOUBLE PRECISION specifies the data type approximate numeric, with implementation-defined precision that is greater than the implementation-defined _precision_ of REAL.
PostgreSQL provides 'real' and 'double precision' but also supports the aliases 'float', 'float8', and 'float4'. The only alias that maps to 'real' is 'float4' (single precision). 'float' maps to 'double precision'.
At least in Python, where 'float' is the language data type for double precision floating point, a database abstraction layer would need to make some bad choices to end up with single precision / Real data type in the persistence layer when talking to a PostgreSQL backend.
The Avro storage enginue uses 'float' for single precision, and only 'double' is mapped to IEEE 754 double precision. At this point it is dubious to me what a python 'float' would get mapped to when writing to Avro.
The following comments are owned by whomever posted them. This site is not responsible for what they say.