Welcome to thatlinuxbox.com Tuesday, May 17 2022 @ 01:30 AM UTC

Floating Point and Decimal Numeric Types

  • Monday, January 10 2022 @ 05:35 PM UTC
  • Contributed by:
  • Views: 158
Fun Stuff @ Work

Share
  • Google Plus
  • Facebook
  • Twitter
  • Reddit
  • LinkedIn
  • Digg

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.

 

Floating Point and Decimal Numeric Types | 0 comments | Create New Account

The following comments are owned by whomever posted them. This site is not responsible for what they say.


User Functions

Login

Connect

thatlinuxbox.com is the home of Dan Stoner's Personal Blog, Photos, and More (opinions, rants, techno-babble, and possibly a few useful tidbits of knowledge).

Questions or Comments about this site? Contact danstoner _ at _ gmail.com.

RSS Feed for this blog

Other places to find me on the web:

Twitter

LinkedIn

GitHub

Support This Site

If you like something that you find on this site, please consider making a purchase through one of the links below or sending me an item from my Amazon Wish List.


The Clymb


Awesome VPS hosting by Linode.com