Working with fixed-point calculations in C

From: Oskar Stenberg <oskar_stenberg(at)outlook(dot)com>
To: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Working with fixed-point calculations in C
Date: 2021-12-07 22:39:41
Message-ID: HE1PR03MB2971DE2527ECE1E99D6C19A8F96E9@HE1PR03MB2971.eurprd03.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

I need to make some fixed-point calculations inside the C code that I'm
developing as an extension to PostgreSQL. I was reading a bit, and if I
understood the datatype NUMBER correctly, it seems to be just what I'm
looking for, a fixed-point datatype. (I couldn't actually find any
thing in the documentation that specifically mentions that it is a
fixed point datatype. But it seems to work the same. So I might be
wrong here and if so please tell me)

Anyway, I thought that it would be good to store the decimal numbers in
the database as the datatype NUMBER, and then just use the C version of
it when I need to work with it in the code. But when I look at the
documentation for writing C functions, I can't find the C version of
it? Is that something that just hasn't made it to the documentation, or
is there a reason for it not being listed there?

Was hoping that I wouldn't need to reinvent the wheel here or include
another library to handle this, as it increases the risk of creating
bugs. But if I have to I'll do it.

Link to the documentation:
https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-BASETYPE
You have to scroll down a little and you will find a table matching
PostgreSQL:s datatypes with the datatypes in C

Best regards
Oskar

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Дмитрий Иванов 2021-12-08 01:39:52 Re: CTE Materialization
Previous Message Zwettler Markus (OIZ) 2021-12-07 16:10:25 error connecting to pgbouncer admin console