Repository: JuliaLang/julia
File: test/math.jl (Julia)

Code before:
            @testset let context=(T, has_fma[T], my_eq)
                @test sind(convert(T,30)) == 0.5
                @test cosd(convert(T,60)) == 0.5
                @test sind(convert(T,150)) == 0.5
                @test my_eq(sinpi(one(T)/convert(T,6)), 0.5)
                @test my_eq(sincospi(one(T)/convert(T,6))[1], 0.5)
                @test_throws DomainError sind(convert(T,Inf))
                @test_throws DomainError cosd(convert(T,Inf))
                fT == Float64 && @test my_eq(cospi(one(T)/convert(T,3)), 0.5)
                fT == Float64 && @test my_eq(sincospi(one(T)/convert(T,3))[2], 0.5)
                T == Rational{Int} && @test my_eq(sinpi(5//6), 0.5)
                T == Rational{Int} && @test my_eq(sincospi(5//6)[1], 0.5)
            end
        end
    end
    scdm = sincosd(missing)
    @test ismissing(scdm[1])
    @test ismissing(scdm[2])
end

@testset "behavior at signed zero of monotonic floating-point functions mapping zero to zero" begin
    @testset "typ: $typ" for typ in (Float16, Float32, Float64)
        @testset "f: $f" for f in (
            # all strictly increasing
            identity, deg2rad, rad2deg, cbrt, log1p, expm1, sinh, tanh, asinh, atanh,
            sin, sind, sinpi, tan, tand, tanpi, asin, asind, atan, atand,
            Base.Fix1(round, typ), Base.Fix1(trunc, typ), ∘(-, -), ∘(-, cosc),
        )
            @testset "s: $s" for s in (-1, 1)
                z = s * typ(0)
                z::typ
                @test z === @inferred f(z)
            end
        end
    end
end

@testset "Integer and Inf args for sinpi/cospi/tanpi/sinc/cosc" begin
    for (sinpi, cospi) in ((sinpi, cospi), (x->sincospi(x)[1], x->sincospi(x)[2]))
        @test sinpi(1) === 0.0
        @test sinpi(-1) === -0.0
        @test cospi(1) == -1
        @test cospi(2) == 1
    end

    @test tanpi(1) === -0.0
    @test tanpi(-1) === 0.0
    @test tanpi(2) === 0.0
    @test tanpi(-2) === -0.0
    @test sinc(1) == 0
    @test sinc(complex(1,0)) == 0

Review comment (suggestion):
```suggestion
            sin, sind, sinpi, tan, tand, tanpi, asin, asind, atan, atand, Base.Fix2(atan, one(typ)), Base.Fix2(atand, one(typ)),
```

Code after:
            @testset let context=(T, has_fma[T], my_eq)
                @test sind(convert(T,30)) == 0.5
                @test cosd(convert(T,60)) == 0.5
                @test sind(convert(T,150)) == 0.5
                @test my_eq(sinpi(one(T)/convert(T,6)), 0.5)
                @test my_eq(sincospi(one(T)/convert(T,6))[1], 0.5)
                @test_throws DomainError sind(convert(T,Inf))
                @test_throws DomainError cosd(convert(T,Inf))
                fT == Float64 && @test my_eq(cospi(one(T)/convert(T,3)), 0.5)
                fT == Float64 && @test my_eq(sincospi(one(T)/convert(T,3))[2], 0.5)
                T == Rational{Int} && @test my_eq(sinpi(5//6), 0.5)
                T == Rational{Int} && @test my_eq(sincospi(5//6)[1], 0.5)
            end
        end
    end
    scdm = sincosd(missing)
    @test ismissing(scdm[1])
    @test ismissing(scdm[2])
end

@testset "behavior at signed zero of monotonic floating-point functions mapping zero to zero" begin
    function rounder(rm::RoundingMode)
        function closure(::Type{T}, x::AbstractFloat) where {T <: AbstractFloat}
            round(T, x, rm)
        end
    end
    rounding_modes = (
        RoundNearest, RoundNearestTiesAway, RoundNearestTiesUp, RoundToZero, RoundFromZero, RoundUp, RoundDown,
    )
    rounders = map(rounder, rounding_modes)
    @testset "typ: $typ" for typ in (Float16, Float32, Float64, BigFloat)
        (n0, n1) = typ.(0:1)
        rounders_typ = Base.Fix1.(rounders, typ)
        @testset "f: $f" for f in (
            # all strictly increasing
            identity, deg2rad, rad2deg, cbrt, log1p, expm1, sinh, tanh, asinh, atanh,
            sin, sind, sinpi, tan, tand, tanpi, asin, asind, atan, atand, Base.Fix2(atan, n1), Base.Fix2(atand, n1),
            Base.Fix1(round, typ), Base.Fix1(trunc, typ), +, ∘(-, -), ∘(-, cosc),
            rounders_typ...,
            Base.Fix1(*, n1), Base.Fix2(*, n1), Base.Fix2(/, n1),
        )
            @testset "s: $s" for s in (-1, 1)
                z = s * n0
                z::typ
                @test z == f(z)::typ
                @test signbit(z) === signbit(f(z))
                isbitstype(typ) &&
                @test z === @inferred f(z)
            end
        end
    end