• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Julia
  • License
    MIT License
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

math with more good bits

DoubleFloats.jl

Math with 85+ accurate bits.

Extended precision float and complex types

  • N.B. Double64 is the most performant type β

Build Status   Docs    Coverage Status    codecov    Package Downloads

Installation

pkg> add DoubleFloats

or

julia> using Pkg
julia> Pkg.add("DoubleFloats")

More Performant Than Float128, BigFloat

these results are from BenchmarkTools, on one machine

There is another package, Quadmath.jl, which exports Float128 from GNU’s libquadmath. Float128s have 6 more significant bits than Double64s, and a much wider exponent range (Double64s exponents have the same range as Float64s). Big128 is BigFloat after setprecision(BigFloat, 128).

Benchmarking: vectors (v) of 1000 values and 50x50 matrices (m).

Double64 Float128 Big128 Double64 Float128 Big128
dot(v,v) 1 3 7 exp.(m) 1 2 6
v .+ v 1 7 16 m * m 1 3 9
v .* v 1 12 25 det(m) 1 5 11

relative performance: smaller is faster, the larger number takes proportionately longer.


Examples

Double64, Double32, Double16

julia> using DoubleFloats

julia> dbl64 = sqrt(Double64(2)); 1 - dbl64 * inv(dbl64)
0.0
julia> dbl32 = sqrt(Double32(2)); 1 - dbl32 * inv(dbl32)
0.0
julia> dbl16 = sqrt(Double16(2)); 1 - dbl16 * inv(dbl16)
0.0

julia> typeof(ans) === Double16
true

note: floating-point constants must be used with care, they are evaluated as Float64 values before additional processing

julia> Double64(0.2)
0.2
julia> showall(ans)
2.0000000000000001110223024625156540e-01

julia> Double64(2)/10
0.2
julia> showall(ans)
1.9999999999999999999999999999999937e-01

julia> df64"0.2"
0.2
julia> showall(ans)
1.9999999999999999999999999999999937e-01

Complex functions

julia> x = ComplexDF64(sqrt(df64"2"), cbrt(df64"3"))
1.4142135623730951 + 1.4422495703074083im
julia> showall(x)
1.4142135623730950488016887242096816 + 1.4422495703074083823216383107800998im

julia> y = acosh(x)
1.402873733241199 + 0.8555178360714634im

julia> x - cosh(y)
7.395570986446986e-32 + 0.0im

show, string, parse

julia> using DoubleFloats

julia> x = sqrt(Double64(2)) / sqrt(Double64(6))
0.5773502691896257

julia> string(x)
"5.7735026918962576450914878050194151e-01"

julia> show(IOContext(Base.stdout,:compact=>false),x)
5.7735026918962576450914878050194151e-01

julia> showall(x)
0.5773502691896257645091487805019415

julia> showtyped(x)
Double64(0.5773502691896257, 3.3450280739356326e-17)

julia> showtyped(parse(Double64, stringtyped(x)))
Double64(0.5773502691896257, 3.3450280739356326e-17)

julia> Meta.parse(stringtyped(x))
:(Double64(0.5773502691896257, 3.3450280739356326e-17))

julia> x = ComplexDF32(sqrt(df32"2"), cbrt(df32"3"))
1.4142135 + 1.4422495im

julia> string(x)
"1.414213562373094 + 1.442249570307406im"

julia> stringtyped(x)
"ComplexD32(Double32(1.4142135, 2.4203233e-8), Double32(1.4422495, 3.3793125e-8))"

see https://juliamath.github.io/DoubleFloats.jl/stable/ for more information


Accuracy

results for f(x), x in 0..1

function abserr relerr
exp 1.0e-31 1.0e-31
log 1.0e-31 1.0e-31
sin 1.0e-31 1.0e-31
cos 1.0e-31 1.0e-31
tan 1.0e-31 1.0e-31
asin 1.0e-31 1.0e-31
acos 1.0e-31 1.0e-31
atan 1.0e-31 1.0e-31
sinh 1.0e-31 1.0e-29
cosh 1.0e-31 1.0e-31
tanh 1.0e-31 1.0e-29
asinh 1.0e-31 1.0e-29
atanh 1.0e-31 1.0e-30

results for f(x), x in 1..2

function abserr relerr
exp 1.0e-30 1.0e-31
log 1.0e-31 1.0e-31
sin 1.0e-31 1.0e-31
cos 1.0e-31 1.0e-28
tan 1.0e-30 1.0e-30
atan 1.0e-31 1.0e-31
sinh 1.0e-30 1.0e-31
cosh 1.0e-30 1.0e-31
tanh 1.0e-31 1.0e-28
asinh 1.0e-31 1.0e-28

isapprox

  • isapprox uses this default rtol=eps(1.0)^(37/64).

Good Ways To Use This

In addition to simply using DoubleFloats and going from there, these two suggestions are easily managed and will go a long way in increasing the robustness of the work and reliability in the computational results.

If your input values are Float64s, map them to Double64s and proceed with your computation. Then unmap your output values as Float64s, do additional work using those Float64s. With Float32 inputs, used Double32s similarly. Where throughput is important, and your algorithms are well-understood, this approach be used with the numerically sensitive parts of your computation only. If you are doing that, be careful to map the inputs to those parts and unmap the outputs from those parts just as described above.

Questions

Usage questions can be posted on the Julia Discourse forum. Use the topic Numerics (a "Discipline") and a put the package name, DoubleFloats, in your question ("topic").

Contributions

Contributions are very welcome, as are feature requests and suggestions. Please open an issue if you encounter any problems.


β: If you want to get involved with moving Double32 performance forward, great. I would provide guidance. Otherwise, for most purposes you are better off using Float64 than Double32 (Float64 has more significant bits, wider exponent range, and is much faster).


More Repositories

1

openlibm

High quality system independent, portable, open source libm implementation
C
512
star
2

Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
Julia
475
star
3

MeasureTheory.jl

"Distributions" that might not add to one.
Julia
388
star
4

SpecialFunctions.jl

Special mathematical functions in Julia
Julia
317
star
5

Polynomials.jl

Polynomial manipulations in Julia
Julia
301
star
6

Roots.jl

Root finding functions for Julia
Julia
299
star
7

Calculus.jl

Calculus functions in Julia
Julia
278
star
8

FFTW.jl

Julia bindings to the FFTW library for fast Fourier transforms
Julia
267
star
9

QuadGK.jl

adaptive 1d numerical Gauss–Kronrod integration in Julia
Julia
267
star
10

Combinatorics.jl

A combinatorics library for Julia
Julia
205
star
11

NFFT.jl

Julia implementation of the Non-equidistant Fast Fourier Transform (NFFT)
Julia
152
star
12

HCubature.jl

pure-Julia multidimensional h-adaptive integration
Julia
151
star
13

Cubature.jl

One- and multi-dimensional adaptive integration routines for the Julia language
Julia
117
star
14

AbstractFFTs.jl

A Julia framework for implementing FFTs
Julia
116
star
15

GSL.jl

Julia interface to the GNU Scientific Library (GSL)
Julia
100
star
16

IntervalSets.jl

Interval Sets for Julia
Julia
93
star
17

Primes.jl

Prime numbers in Julia
Julia
87
star
18

FixedPointNumbers.jl

fixed point types for julia
Julia
80
star
19

Bessels.jl

Bessel functions for real arguments and orders
Julia
78
star
20

RandomMatrices.jl

Random matrices package for Julia
Julia
77
star
21

Sobol.jl

generation of Sobol low-discrepancy sequence (LDS) for the Julia language
Julia
74
star
22

IntelVectorMath.jl

Julia bindings for the Intel Vector Math Library
Julia
72
star
23

HypergeometricFunctions.jl

A Julia package for calculating hypergeometric functions
Julia
67
star
24

AccurateArithmetic.jl

Calculate with error-free, faithful, and compensated transforms and extended significands.
Julia
64
star
25

Richardson.jl

Richardson extrapolation in Julia
Julia
62
star
26

FastChebInterp.jl

fast multidimensional Chebyshev interpolation and regression in Julia
Julia
58
star
27

Decimals.jl

Pure Julia decimal arithmetic library.
Julia
57
star
28

DecFP.jl

Julia IEEE decimal floating-point via the Intel decimal-float library
Julia
55
star
29

Yeppp.jl

Yeppp! bindings
Julia
54
star
30

NaNMath.jl

Julia math built-ins which return NaN and accumulator functions which ignore NaN
Julia
53
star
31

BFloat16s.jl

Julia implementation for the BFloat16 number type
Julia
48
star
32

FastPow.jl

optimal addition-chain exponentiation for Julia
Julia
41
star
33

Tau.jl

A Julia module providing the definition of the circle constant Tau (2Ï€)
Julia
36
star
34

Quadmath.jl

Float128 and libquadmath for the Julia language
Julia
35
star
35

Hadamard.jl

Fast Walsh-Hadamard transforms for the Julia language
Julia
35
star
36

openspecfun

A collection of special mathematical functions
Fortran
33
star
37

FixedPointDecimals.jl

Julia fixed-point decimals built from integers
Julia
33
star
38

ChangePrecision.jl

macro to change the default floating-point precision in Julia code
Julia
33
star
39

InverseLaplace.jl

Inverse Laplace transform
Julia
30
star
40

InverseFunctions.jl

Interface for function inversion in Julia
Julia
29
star
41

MeasureBase.jl

Julia
26
star
42

DoubleDouble.jl

Extended precision arithmetic for Julia (deprecated)
Julia
26
star
43

Libm.jl

A pure Julia math library
Julia
24
star
44

TensorCore.jl

Lightweight package for sharing tensor-algebra definitions
Julia
23
star
45

LambertW.jl

Lambert W mathematical function
Julia
21
star
46

KahanSummation.jl

Sum and cumulative sum using the Kahan-Babuska-Neumaier algorithm
Julia
19
star
47

Float8s.jl

A number format that you can count with your fingers.
Julia
17
star
48

Infinities.jl

A Julia package for representing infinity in all its forms
Julia
17
star
49

Xsum.jl

exactly rounded double-precision summation for Julia
Julia
16
star
50

IrrationalConstants.jl

defines additional irrationals
Julia
16
star
51

FunctionAccuracyTests.jl

ULP testing for Floating Point special functions.
Julia
13
star
52

DensityInterface.jl

Interface for mathematical/statistical densities in Julia
Julia
12
star
53

ChangesOfVariables.jl

Interface for transformation functions in Julia
Julia
11
star
54

CheckedArithmetic.jl

Utilities for handling arithmetic overflow
Julia
10
star
55

RoundingIntegers.jl

Integer types that automatically round assigned values
Julia
10
star
56

IntegerMathUtils.jl

Julia
6
star
57

MittagLeffler.jl

Mittag-Leffler function
Julia
6
star
58

ILog2.jl

integer valued base 2 logarithm
Julia
5
star
59

FunctionZeros.jl

Zeros of Bessel J and Y functions
Julia
4
star
60

RealDot.jl

Compute `real(dot(x, y))` efficiently.
Julia
4
star
61

FFTWBuilder

binary builder for FFTW.jl package
Julia
2
star
62

OpenlibmBuilder

Julia
2
star
63

Roadmap.jl

1
star
64

OpenspecfunBuilder

Julia
1
star
65

DSFMTBuilder

Julia
1
star
66

MPFRBuilder

Julia
1
star
67

GMPBuilder

Julia
1
star