Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ uuid = "be4d8f0f-7fa4-5f49-b795-2f01399ab2dd"
version = "1.1.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[weakdeps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[extensions]
QuadmathSpecialFunctionsExt = ["SpecialFunctions"]
QuadmathPrintfExt = ["Printf"]
QuadmathRandomExt = ["Random"]

[compat]
Aqua = "0.6, 0.8"
Compat = "4.4"
Printf = "<0.0.1, 1"
Random = "<0.0.1, 1"
SpecialFunctions = "2.0"
Test = "<0.0.1, 1"
julia = "1.6"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "SpecialFunctions"]
test = ["Aqua", "Test", "SpecialFunctions", "Random", "Printf"]
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

[![CI](https://github.com/JuliaMath/Quadmath.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaMath/Quadmath.jl/actions/workflows/CI.yml)

This is a Julia interface to libquadmath, providing a `Float128` type corresponding to the IEEE754 binary128 floating point format.
This is a Julia interface to the IEEE 754 binary128 floating point format, backed by libquadmath (or libm for some architectures). It provides a `Float128` type and associated functionality.

## Support

Quadmath currently works on x86_64 Linux, macOS, and Windows.
Quadmath supports x86_64 and AArch64.

- It may require a new-ish version of gcc which supports `__float128` type.
- It has not been tested on 32 bit Linux.
- It does not work on (32-bit) ARM due to the lack of libquadmath support for that platform.
- On AArch64 Linux and FreeBSD, libquadmath is not available, so `long double` functions from libm are used instead. Unlike x86_64, `long double` on AArch64 is IEEE 754 binary128.
- On x86_64, it may require gcc 4.3 or later for the `__float128` type.
- It has not been tested on 32-bit x86 Linux.
- It does not work on 32-bit ARM due to the lack of libquadmath support for that platform.

## Installation

Quadmath.jl is now a registered package, so can be added via `]add Quadmath`.
Quadmath.jl is a registered package, so can be added via `]add Quadmath`.

## Acknowledgements

Expand Down
7 changes: 7 additions & 0 deletions ext/QuadmathPrintfExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module QuadmathPrintfExt

using Quadmath, Printf

Printf.tofloat(x::Float128) = BigFloat(x)

end
13 changes: 13 additions & 0 deletions ext/QuadmathRandomExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module QuadmathRandomExt

using Quadmath, Random

function Random.rand(rng::AbstractRNG, s::Random.SamplerTrivial{Random.CloseOpen01{Float128}})
u = rand(rng, UInt128)
x = (reinterpret(Float128, u & Base.significand_mask(Float128)
| Base.exponent_one(Float128))
- one(Float128))
return x
end

end
16 changes: 1 addition & 15 deletions src/Quadmath.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Quadmath
using Compat: @assume_effects
using Base: @assume_effects

export Float128, ComplexF128, Inf128, NaN128

Expand All @@ -21,7 +21,6 @@ import Base: (*), +, -, /, <, <=, ==, ^, convert,
Int32, Int64, Float16, Float32, Float64, BigFloat, BigInt

using Base.Meta
using Random

# On AArch64, long double is IEEE binary128 and we don't have a separate libquadmath
const USE_LONG_DOUBLE = Sys.ARCH === :aarch64 && Sys.isunix() && !Sys.isapple()
Expand Down Expand Up @@ -570,14 +569,6 @@ function decompose(x::Float128)::Tuple{Int128, Int, Int}
s, e - 16495 + (e == 0), d
end

function Random.rand(rng::AbstractRNG, s::Random.SamplerTrivial{Random.CloseOpen01{Float128}})
u = rand(rng, UInt128)
x = (reinterpret(Float128, u & Base.significand_mask(Float128)
| Base.exponent_one(Float128))
- one(Float128))
return x
end

# TODO: need to do this better
function parse(::Type{Float128}, s::AbstractString)
Float128(@quad_ccall(@autoql(strto)(s::Cstring, C_NULL::Ptr{Ptr{Cchar}})::Cfloat128))
Expand Down Expand Up @@ -616,9 +607,4 @@ function show(io::IO, x::Float128)
end
print(io::IO, b::Float128) = print(io, string(b))

include("printf.jl")

if !isdefined(Base, :get_extension)
include("../ext/QuadmathSpecialFunctionsExt.jl")
end
end # module Quadmath
3 changes: 0 additions & 3 deletions src/printf.jl

This file was deleted.

Loading