Skip to content

rjfarmer/pyQuadp

Repository files navigation

Continuous Integration Coverage Status Python versions gfortran versions

pyQuadp

Python interface to gcc's libquadmath for quad (128-bit) precision maths.

Build

python -m build
python -m pip install . 

Package is not yet available on pypi.

This package requires quadmath.h and libquadmath.so. This might come installed with your installation of gcc/gfortran from your package manager. Or it might require a separate installation. This should be installed before trying to install the Python package.

Fedora

sudo dnf install libquadmath libquadmath-devel

Usage

qfloat

A quad precision number is created by passing either a int, float, or string to qfloat:

import pyquadp

q = pyquadp.qfloat(1)
q = pyquadp.qfloat(1.0)
q = pyquadp.qfloat('1')

A qfloat implements Python's NumberProtocol, thus it can be used like any other number, either with basic math operations or in rich comparisons:

q1 = pyquadp.qfloat(1)
q2 = pyquadp.qfloat(2)

q1+q2 # pyquadp.qfloat(3)
q1*q2  # pyquadp.qfloat(2)
q1+=q2 # pyquadp.qfloat(3)

q1 <= q2 # True
q1 == q2 # False

str(q) # "1.000000000000000000000000000000000000e+00"

qcmplx

A quad precision number is created by passing either a complex variable or two ints, floats, strs, or qfloats to qcmplx:

import pyquadp

q = pyquadp.qcmplx(complex(1,1))
q = pyquadp.qcmplx(1,1.0)
q = pyquadp.qcmplx('1',1.0)
q = pyquadp.qcmplx('1','1')
q = pyquadp.qcmplx(pyquadp.qfloat(1), pyquadp.qfloat('1'))

Note that strings must be split into two components. There is no support for 1+1j (unless passed via complex('1+1j'))

Math libraries

The qmath provides the union of math operations from Python's math library and the routines provided in libquadmath. qmath provides routines for qfloat, while complex numbers are handled by qcmath versions.

Where possible functions accessed via the Python name follows Python's conventions regarding behavior of exceptional values. While routines from libquadmath (those ending in q) follows libquadmath's conventions.

Routines from Python's math library

Name Implemented Descritpion
ceil ✔️
comb
copysign ✔️
fabs ✔️
factorial
floor ✔️
fmod ✔️
frexp ✔️
fsum
gcd
isclose
isfinite
isinf ✔️
isnan ✔️
isqrt
lcm
ldexp ✔️
modf ✔️
nextafter ✔️
perm
prod
remainder ✔️
trunc ✔️
ulp
cbrt ✔️
exp ✔️
exp2 ✔️
expm1 ✔️
log ✔️
log1p ✔️
log2 ✔️
log10 ✔️
pow ✔️
sqrt ✔️
acos ✔️
asin ✔️
atan ✔️
atan2 ✔️
cos ✔️
dist
hypot ✔️
sin ✔️
tan ✔️
degress
radians
acosh ✔️
asinh ✔️
atanh ✔️
cosh ✔️
sinh ✔️
tanh ✔️
erf ✔️
erfc ✔️
gamma ✔️
lgamma ✔️
pi ✔️
e ✔️
tau ✔️
inf ✔️
nan ✔️

Routines from gcc's libquadthmath library

Name Implemented
acosq ✔️
acoshq ✔️
asinq ✔️
asinhq ✔️
atanq ✔️
atanhq ✔️
atan2q ✔️
cbrtq ✔️
ceilq ✔️
copysignq ✔️
coshq ✔️
cosq ✔️
erfq ✔️
erfcq ✔️
exp2q ✔️
expq ✔️
expm1q ✔️
fabsq ✔️
fdimq ✔️
finiteq ✔️
floorq ✔️
fmaq ✔️
fmaxq ✔️
fminq ✔️
fmodq ✔️
frexpq ✔️
hypotq ✔️
ilogbq ✔️
isinfq ✔️
isnanq ✔️
issignalingq ✔️
j0q ✔️
j1q ✔️
jnq ✔️
ldexpq ✔️
lgammaq ✔️
llrintq ✔️
llroundq ✔️
logbq ✔️
logq ✔️
log10q ✔️
log1pq ✔️
log2q ✔️
lrintq ✔️
lroundq ✔️
modfq ✔️
nanq ✔️
nearbyintq ✔️
nextafterq ::heavy_check_mark:
powq ✔️
remainderq ✔️
remquoq ✔️
rintq ✔️
roundq ✔️
scalblnq ✔️
scalbnq ✔️
signbitq ✔️
sincosq ✔️
sinhq ✔️
sinq ✔️
sqrtq ✔️
tanq ✔️
tanhq ✔️
tgammaq ✔️
truncq ✔️
y0q ✔️
y1q ✔️
ynq ✔️

Routines from Python's complex math cmath library

These are available from qcmath

Name Implemented Descritpion
phase ✔️
polar ✔️
rect ✔️
exp ✔️
log ✔️
log10 ✔️
sqrt ✔️
acos ✔️
asin ✔️
atan ✔️
cos ✔️
sin ✔️
tan ✔️
acosh ✔️
asinh ✔️
atanh ✔️
cosh ✔️
sinh ✔️
tanh ✔️
isfinite ✔️
isinf ✔️
isnan ✔️
isclose
pi ✔️
e ✔️
tau ✔️
inf ✔️
infj ✔️
nan ✔️
nanj ✔️

Routines from complex math libquadthmath library

These are available from qcmath

Name Implemented Descritpion
cabsq ✔️ complex absolute value function
cargq ✔️ calculate the argument
cimagq ✔️ imaginary part of complex number
crealq ✔️ real part of complex number
cacoshq ✔️ complex arc hyperbolic cosine function
cacosq ✔️ complex arc cosine function
casinhq ✔️ complex arc hyperbolic sine function
casinq ✔️ complex arc sine function
catanhq ✔️ complex arc hyperbolic tangent function
catanq ✔️ complex arc tangent function
ccosq: ✔️ complex cosine function
ccoshq ✔️ complex hyperbolic cosine function
cexpq ✔️ complex exponential function
cexpiq ✔️ computes the exponential function of i times a real value
clogq ✔️ complex natural logarithm
clog10q ✔️ complex base 10 logarithm
conjq ✔️ complex conjugate function
cpowq ✔️ complex power function
cprojq ✔️ project into Riemann Sphere
csinq ✔️ complex sine function
csinhq ✔️ complex hyperbolic sine function
csqrtq ✔️ complex square root
ctanq ✔️ complex tangent function
ctanhq ✔️ complex hyperbolic tangent function

Constants from libquadthmath library.

The following constants are availbe both in qmath and qcmath

Name Implemented Descritpion
FLT128_MAX ✔️ largest finite number
FLT128_MIN ✔️ smallest positive number with full precision
FLT128_EPSILON ✔️ difference between 1 and the next larger representable number
FLT128_DENORM_MIN ✔️ smallest positive denormalized number
FLT128_MANT_DIG ✔️ number of digits in the mantissa (bit precision)
FLT128_MIN_EXP ✔️ maximal negative exponent
FLT128_MAX_EXP ✔️ maximal positive exponent
FLT128_DIG ✔️ number of decimal digits in the mantissa
FLT128_MIN_10_EXP ✔️ maximal negative decimal exponent
FLT128_MAX_10_EXP ✔️ maximal positive decimal exponent
M_Eq ✔️ the constant e (Euler’s number)
M_LOG2Eq ✔️ binary logarithm of 2
M_LOG10Eq ✔️ common, decimal logarithm of 2
M_LN2q ✔️ natural logarithm of 2
M_LN10q ✔️ natural logarithm of 10
M_PIq ✔️ pi
M_PI_2q ✔️ pi divided by two
M_PI_4q ✔️ pi divided by four
M_1_PIq ✔️ one over pi
M_2_PIq ✔️ one over two pi
M_2_SQRTPIq ✔️ two over square root of pi
M_SQRT2q ✔️ square root of 2
M_SQRT1_2q ✔️ one over square root of 2

About

Python bindings for gcc's libquadmath

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages