Question about new C and PostgreSQL High Precision types.

A Z poweruserm at
Wed Aug 25 02:13:19 UTC 2021


I am trying to find a volunteer or more to create a multiplatform

PostgreSQL extension, to be coded in C, to support

High Extension Integer and Rational (mixed Integer

and finite Decimal) number specifying, arithmetic

operating, and function calling, comparing and casting

within standard installations of PostgreSQL.

The following is a specification of what is needed:


-Integer (MPZ) Z, or Rational Decimal Q (MPQ) numbers support.

The fact is that finite or infinitely recurring Rational Numbers and Irrational Numbers

can be appropriately truncated, by a precision value, to obtain an approximating value,

a finite Rational value, with integer and decimal parts at the same time.  This

is what I am after here.

-A defaulting number of significant figures (precision), say, 50, and a constructor for otherwise.

MPZ(1000) or MPQ(1000), or MPZ, MPQ just on their own, with no more specified.

-Value assignment by =. The ability to specify type without any text data in a constructor.

-Base 10 Arithmetic and comparisons support on Base 10 Integer and Rational Decimal numbers.

+,-,*,/,%,^,=,!=,<>,>,<,>=,<=, ::

These include full division and integer only division, with no remainder.

-When operating on two multiprecision numbers, you take the largest precision of the two

number arguments, by default, for the precision of the result. If this precision is not

large enough for the meaningful result, in terms of all integer places and at least one

decimal place, there should be a precision exception. Because of this, you need the

option to learn of and enlarge the larger of the two precisions, and to try again.

Which should of course be in an exception catching block. To allow calls such as

the two following ones:

setPrecision(MPQ value1, MPZ getPrecision(MPQ value1) + 1);

setPrecision(MPZ value2, MPZ getPrecision(MPZ value2) + 1);

-Mathematical and Operational functions support:

cast(text as MPZ) returns MPZ;

cast(text as MPQ) returns MPQ;

cast(MPQ as text) returns text;

cast(MPZ as text) returns text;

cast(MPZ as MPQ) returns MPQ;

cast(MPQ as MPZ) returns MPZ;

getPrecision(MPZ input) returns MPZ output;

getPrecision(MPQ input) returns MPZ output;

setPrecision(MPZ value, MPZ precision);

setPrecision(MPQ value, MPZ precision);

sign(MPQ input) returns MPQ;

abs(MPQ input) returns MPQ;

ceil(MPQ input) returns MPQ;

floor(MPQ input) returns MPQ;

round(MPQ input) returns MPZ;

pi(MPZ places) returns MPQ;

e(MPZ places) returns MPQ;

power(MPQ base, MPQ exponent) returns MPQ;

sqrt(MPQ input) returns MPQ

nroot(MPZ theroot, MPQ input) returns MPQ;

log10(MPQ input) returns MPQ;

loge(MPQ input) returns MPQ;

log2(MPQ input) returns MPQ;

factorial(MPZ input) returns MPZ;

degrees(MPQ input) returns MPQ;

radians(MPQ input) returns MPQ;

sind(MPQ input) returns MPQ;

cosd(MPQ input) returns MPQ;

tand(MPQ input) returns MPQ;

asind(MPQ input) returns MPQ;

acosd(MPQ input) returns MPQ;

atand(MPQ input) returns MPQ;

sinr(MPQ input) returns MPQ;

cosr(MPQ input) returns MPQ;

tanr(MPQ input) returns MPQ;

asinr(MPQ input) returns MPQ;

acosr(MPQ input) returns MPQ;

atanr(MPQ input) returns MPQ;

Arithmetic Operations:

Integer Division:

Modulus Operation:

Factorial Operation:

Comparison Operators:



Elementary Functions:

-Ease of installation support. Particularly for Windows and Linux. *.exe, *.msi or *.rpm, *.deb, *.bin installers.

With a PostgreSQL standard installation.  With instructions in a README about how to install the extension

on a Hard Drive and how to load and install the extension in PostgreSQL.

The following chart could be used to help test trigonometry outputs:


Is there anyone at gmp who knows enough about gmp, C, and multiplatform PostgreSQL extentions

who could volunteer for this project?


More information about the gmp-discuss mailing list