Skip to content

Commit 13c71b4

Browse files
committed
add trig pi and degree functions
1 parent 2cb01fb commit 13c71b4

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

base/mpfr.jl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import
1616
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, lerpi,
1717
cbrt, typemax, typemin, unsafe_trunc, floatmin, floatmax, rounding,
1818
setrounding, maxintfloat, widen, significand, frexp, tryparse, iszero,
19-
isone, big, _string_n, decompose, minmax
19+
isone, big, _string_n, decompose, minmax,
20+
sinpi, cospi, sind, cosd, tand, asind, acosd, atand
2021

2122
import ..Rounding: rounding_raw, setrounding_raw
2223

@@ -780,7 +781,7 @@ function sum(arr::AbstractArray{BigFloat})
780781
end
781782

782783
# Functions for which NaN results are converted to DomainError, following Base
783-
for f in (:sin, :cos, :tan, :sec, :csc, :acos, :asin, :atan, :acosh, :asinh, :atanh)
784+
for f in (:sin, :cos, :tan, :sec, :csc, :acos, :asin, :atan, :acosh, :asinh, :atanh, :sinpi, :cospi)
784785
@eval begin
785786
function ($f)(x::BigFloat)
786787
isnan(x) && return x
@@ -798,6 +799,32 @@ function atan(y::BigFloat, x::BigFloat)
798799
return z
799800
end
800801

802+
# degree functions
803+
for f in (:sin, :cos, :tan)
804+
@eval begin
805+
function ($(Symbol(f,:d)))(x::BigFloat)
806+
isnan(x) && return x
807+
z = BigFloat()
808+
ccall(($(string(:mpfr_,f,:u)), :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, x, 360, ROUNDING_MODE[])
809+
isnan(z) && throw(DomainError(x, "NaN result for non-NaN input."))
810+
return z
811+
end
812+
function ($(Symbol(:a,f,:d)))(x::BigFloat)
813+
isnan(x) && return x
814+
z = BigFloat()
815+
ccall(($(string(:mpfr_a,f,:u)), :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, x, 360, ROUNDING_MODE[])
816+
isnan(z) && throw(DomainError(x, "NaN result for non-NaN input."))
817+
return z
818+
end
819+
end
820+
end
821+
function atand(y::BigFloat, x::BigFloat)
822+
z = BigFloat()
823+
ccall((:mpfr_atan2u, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Ref{BigFloat}, Culong, MPFRRoundingMode), z, y, x, 360, ROUNDING_MODE[])
824+
return z
825+
end
826+
827+
801828
# Utility functions
802829
==(x::BigFloat, y::BigFloat) = ccall((:mpfr_equal_p, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), x, y) != 0
803830
<=(x::BigFloat, y::BigFloat) = ccall((:mpfr_lessequal_p, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), x, y) != 0

0 commit comments

Comments
 (0)