all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 73a395c89e93aed6e5d5aebdd98f5f0f896cb092 11144 bytes (raw)
name: gnu/packages/patches/julia-Use-MPFR-4.2.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
 
This patch backports part of Julia upstream commit:

    1e5fdb29f8858f3244f6aff116ee12e4c8247f3a
    Author:     Simon Byrne <simon.byrne@gmail.com>
    AuthorDate: Tue Jan 10 14:52:36 2023 -0800
    Commit:     GitHub <noreply@github.com>
    CommitDate: Tue Jan 10 17:52:36 2023 -0500

    update MPFR to 4.2.0 (#48165)

    Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>

    6 files changed, 112 insertions(+), 79 deletions(-)
    base/mpfr.jl                     | 34 ++++++++++++++--
    deps/checksums/mpfr              | 68 ++++++++++++++++----------------
    deps/mpfr.version                |  2 +-
    stdlib/MPFR_jll/Project.toml     |  2 +-
    stdlib/MPFR_jll/test/runtests.jl |  2 +-
    test/math.jl                     | 83 +++++++++++++++++++++-------------------


diff -ur julia-1.8.3-orig/base/mpfr.jl julia-1.8.3-patch/base/mpfr.jl
--- julia-1.8.3-orig/base/mpfr.jl	2023-04-13 17:50:58.394891391 +0200
+++ julia-1.8.3-patch/base/mpfr.jl	2023-04-13 20:42:52.551833467 +0200
@@ -16,7 +16,8 @@
         cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, lerpi,
         cbrt, typemax, typemin, unsafe_trunc, floatmin, floatmax, rounding,
         setrounding, maxintfloat, widen, significand, frexp, tryparse, iszero,
-        isone, big, _string_n, decompose
+        isone, big, _string_n, decompose, minmax,
+        sinpi, cospi, sincospi, sind, cosd, tand, asind, acosd, atand
 
 import ..Rounding: rounding_raw, setrounding_raw
 
@@ -745,7 +746,7 @@
 end
 
 # Functions for which NaN results are converted to DomainError, following Base
-for f in (:sin, :cos, :tan, :sec, :csc, :acos, :asin, :atan, :acosh, :asinh, :atanh)
+for f in (:sin, :cos, :tan, :sec, :csc, :acos, :asin, :atan, :acosh, :asinh, :atanh, :sinpi, :cospi)
     @eval begin
         function ($f)(x::BigFloat)
             isnan(x) && return x
@@ -756,6 +757,7 @@
         end
     end
 end
+sincospi(x::BigFloat) = (sinpi(x), cospi(x))
 
 function atan(y::BigFloat, x::BigFloat)
     z = BigFloat()
@@ -763,6 +765,32 @@
     return z
 end
 
+# degree functions
+for f in (:sin, :cos, :tan)
+    @eval begin
+        function ($(Symbol(f,:d)))(x::BigFloat)
+            isnan(x) && return x
+            z = BigFloat()
+            ccall(($(string(:mpfr_,f,:u)), :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, x, 360, ROUNDING_MODE[])
+            isnan(z) && throw(DomainError(x, "NaN result for non-NaN input."))
+            return z
+        end
+        function ($(Symbol(:a,f,:d)))(x::BigFloat)
+            isnan(x) && return x
+            z = BigFloat()
+            ccall(($(string(:mpfr_a,f,:u)), :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, x, 360, ROUNDING_MODE[])
+            isnan(z) && throw(DomainError(x, "NaN result for non-NaN input."))
+            return z
+        end
+    end
+end
+function atand(y::BigFloat, x::BigFloat)
+    z = BigFloat()
+    ccall((:mpfr_atan2u, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, y, x, 360, ROUNDING_MODE[])
+    return z
+end
+
+
 # Utility functions
 ==(x::BigFloat, y::BigFloat) = ccall((:mpfr_equal_p, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), x, y) != 0
 <=(x::BigFloat, y::BigFloat) = ccall((:mpfr_lessequal_p, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), x, y) != 0
@@ -1018,7 +1046,7 @@
     isfinite(x) || return string(Float64(x))
     _prettify_bigfloat(string_mpfr(x, fmt))
 end
-_string(x::BigFloat) = _string(x, "%.Re")
+_string(x::BigFloat) = _string(x, "%Re")
 _string(x::BigFloat, k::Integer) = _string(x, "%.$(k)Re")
 
 string(b::BigFloat) = _string(b)
diff -ur julia-1.8.3-orig/test/math.jl julia-1.8.3-patch/test/math.jl
--- julia-1.8.3-orig/test/math.jl	2023-04-13 17:50:58.382891276 +0200
+++ julia-1.8.3-patch/test/math.jl	2023-04-13 21:13:55.377279761 +0200
@@ -411,47 +411,51 @@
     @test rad2deg(pi + (pi/3)*im) ≈ 180 + 60im
 end
 
+# ensure zeros are signed the same
+⩲(x,y) = typeof(x) == typeof(y) && x == y && signbit(x) == signbit(y)
+⩲(x::Tuple, y::Tuple) = length(x) == length(y) && all(map(⩲,x,y))
+
 @testset "degree-based trig functions" begin
-    @testset "$T" for T = (Float32,Float64,Rational{Int})
+    @testset "$T" for T = (Float32,Float64,Rational{Int},BigFloat)
         fT = typeof(float(one(T)))
         fTsc = typeof( (float(one(T)), float(one(T))) )
         for x = -400:40:400
-            @test sind(convert(T,x))::fT ≈ convert(fT,sin(pi/180*x)) atol=eps(deg2rad(convert(fT,x)))
-            @test cosd(convert(T,x))::fT ≈ convert(fT,cos(pi/180*x)) atol=eps(deg2rad(convert(fT,x)))
+            @test sind(convert(T,x))::fT ≈ sin(pi*convert(fT,x)/180) atol=eps(deg2rad(convert(fT,x)))
+            @test cosd(convert(T,x))::fT ≈ cos(pi*convert(fT,x)/180) atol=eps(deg2rad(convert(fT,x)))
 
             s,c = sincosd(convert(T,x))
-            @test s::fT ≈ convert(fT,sin(pi/180*x)) atol=eps(deg2rad(convert(fT,x)))
-            @test c::fT ≈ convert(fT,cos(pi/180*x)) atol=eps(deg2rad(convert(fT,x)))
+            @test s::fT ≈ sin(pi*convert(fT,x)/180) atol=eps(deg2rad(convert(fT,x)))
+            @test c::fT ≈ cos(pi*convert(fT,x)/180) atol=eps(deg2rad(convert(fT,x)))
         end
         @testset "sind" begin
-            @test sind(convert(T,0.0))::fT === zero(fT)
-            @test sind(convert(T,180.0))::fT === zero(fT)
-            @test sind(convert(T,360.0))::fT === zero(fT)
-            T != Rational{Int} && @test sind(convert(T,-0.0))::fT === -zero(fT)
-            @test sind(convert(T,-180.0))::fT === -zero(fT)
-            @test sind(convert(T,-360.0))::fT === -zero(fT)
+            @test sind(convert(T,0.0))::fT ⩲ zero(fT)
+            @test sind(convert(T,180.0))::fT ⩲ zero(fT)
+            @test sind(convert(T,360.0))::fT ⩲ zero(fT)
+            T != Rational{Int} && @test sind(convert(T,-0.0))::fT ⩲ -zero(fT)
+            @test sind(convert(T,-180.0))::fT ⩲ -zero(fT)
+            @test sind(convert(T,-360.0))::fT ⩲ -zero(fT)
             if T <: AbstractFloat
                 @test isnan(sind(T(NaN)))
             end
         end
         @testset "cosd" begin
-            @test cosd(convert(T,90))::fT === zero(fT)
-            @test cosd(convert(T,270))::fT === zero(fT)
-            @test cosd(convert(T,-90))::fT === zero(fT)
-            @test cosd(convert(T,-270))::fT === zero(fT)
+            @test cosd(convert(T,90))::fT ⩲ zero(fT)
+            @test cosd(convert(T,270))::fT ⩲ zero(fT)
+            @test cosd(convert(T,-90))::fT ⩲ zero(fT)
+            @test cosd(convert(T,-270))::fT ⩲ zero(fT)
             if T <: AbstractFloat
                 @test isnan(cosd(T(NaN)))
             end
         end
         @testset "sincosd" begin
-            @test sincosd(convert(T,-360))::fTsc === ( -zero(fT),  one(fT) )
-            @test sincosd(convert(T,-270))::fTsc === (   one(fT), zero(fT) )
-            @test sincosd(convert(T,-180))::fTsc === ( -zero(fT), -one(fT) )
-            @test sincosd(convert(T, -90))::fTsc === (  -one(fT), zero(fT) )
-            @test sincosd(convert(T,   0))::fTsc === (  zero(fT),  one(fT) )
-            @test sincosd(convert(T,  90))::fTsc === (   one(fT), zero(fT) )
-            @test sincosd(convert(T, 180))::fTsc === (  zero(fT), -one(fT) )
-            @test sincosd(convert(T, 270))::fTsc === (  -one(fT), zero(fT) )
+            @test sincosd(convert(T,-360))::fTsc ⩲ ( -zero(fT),  one(fT) )
+            @test sincosd(convert(T,-270))::fTsc ⩲ (   one(fT), zero(fT) )
+            @test sincosd(convert(T,-180))::fTsc ⩲ ( -zero(fT), -one(fT) )
+            @test sincosd(convert(T, -90))::fTsc ⩲ (  -one(fT), zero(fT) )
+            @test sincosd(convert(T,   0))::fTsc ⩲ (  zero(fT),  one(fT) )
+            @test sincosd(convert(T,  90))::fTsc ⩲ (   one(fT), zero(fT) )
+            @test sincosd(convert(T, 180))::fTsc ⩲ (  zero(fT), -one(fT) )
+            @test sincosd(convert(T, 270))::fTsc ⩲ (  -one(fT), zero(fT) )
             if T <: AbstractFloat
                 @test_throws DomainError sincosd(T(Inf))
                 @test all(isnan.(sincosd(T(NaN))))
@@ -463,22 +467,22 @@
             "sincospi" => (x->sincospi(x)[1], x->sincospi(x)[2])
         )
             @testset "pi * $x" for x = -3:0.3:3
-                @test sinpi(convert(T,x))::fT ≈ convert(fT,sin(pi*x)) atol=eps(pi*convert(fT,x))
-                @test cospi(convert(T,x))::fT ≈ convert(fT,cos(pi*x)) atol=eps(pi*convert(fT,x))
+                @test sinpi(convert(T,x))::fT ≈ sin(pi*convert(fT,x)) atol=eps(pi*convert(fT,x))
+                @test cospi(convert(T,x))::fT ≈ cos(pi*convert(fT,x)) atol=eps(pi*convert(fT,x))
             end
 
-            @test sinpi(convert(T,0.0))::fT === zero(fT)
-            @test sinpi(convert(T,1.0))::fT === zero(fT)
-            @test sinpi(convert(T,2.0))::fT === zero(fT)
-            T != Rational{Int} && @test sinpi(convert(T,-0.0))::fT === -zero(fT)
-            @test sinpi(convert(T,-1.0))::fT === -zero(fT)
-            @test sinpi(convert(T,-2.0))::fT === -zero(fT)
+            @test sinpi(convert(T,0.0))::fT ⩲ zero(fT)
+            @test sinpi(convert(T,1.0))::fT ⩲ zero(fT)
+            @test sinpi(convert(T,2.0))::fT ⩲ zero(fT)
+            T != Rational{Int} && @test sinpi(convert(T,-0.0))::fT ⩲ -zero(fT)
+            @test sinpi(convert(T,-1.0))::fT ⩲ -zero(fT)
+            @test sinpi(convert(T,-2.0))::fT ⩲ -zero(fT)
             @test_throws DomainError sinpi(convert(T,Inf))
 
-            @test cospi(convert(T,0.5))::fT === zero(fT)
-            @test cospi(convert(T,1.5))::fT === zero(fT)
-            @test cospi(convert(T,-0.5))::fT === zero(fT)
-            @test cospi(convert(T,-1.5))::fT === zero(fT)
+            @test cospi(convert(T,0.5))::fT ⩲ zero(fT)
+            @test cospi(convert(T,1.5))::fT ⩲ zero(fT)
+            @test cospi(convert(T,-0.5))::fT ⩲ zero(fT)
+            @test cospi(convert(T,-1.5))::fT ⩲ zero(fT)
             @test_throws DomainError cospi(convert(T,Inf))
         end
         @testset "Check exact values" begin
@@ -489,8 +493,8 @@
             @test sincospi(one(T)/convert(T,6))[1] == 0.5
             @test_throws DomainError sind(convert(T,Inf))
             @test_throws DomainError cosd(convert(T,Inf))
-            T != Float32 && @test cospi(one(T)/convert(T,3)) == 0.5
-            T != Float32 && @test sincospi(one(T)/convert(T,3))[2] == 0.5
+            fT == Float64 && @test isapprox(cospi(one(T)/convert(T,3)), 0.5)
+            fT == Float64 && @test isapprox(sincospi(one(T)/convert(T,3))[2], 0.5)
             T == Rational{Int} && @test sinpi(5//6) == 0.5
             T == Rational{Int} && @test sincospi(5//6)[1] == 0.5
         end
@@ -538,8 +542,8 @@
             end
         end
     end
-    @test @inferred(sinc(0//1)) === 1.0
-    @test @inferred(cosc(0//1)) === -0.0
+    @test @inferred(sinc(0//1)) ⩲ 1.0
+    @test @inferred(cosc(0//1)) ⩲ -0.0
 
     # test right before/after thresholds of Taylor series
     @test sinc(0.001) ≈ 0.999998355066745 rtol=1e-15

debug log:

solving 73a395c89e ...
found 73a395c89e in https://git.savannah.gnu.org/cgit/guix.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.