~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to base/math.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
# non-type specific math functions
27
27
 
28
28
clamp(x::Real, lo::Real, hi::Real) = (x > hi ? hi : (x < lo ? lo : x))
 
29
clamp{T<:Real}(x::AbstractArray{T,1}, lo::Real, hi::Real) = [clamp(xx, lo, hi) for xx in x]
 
30
clamp{T<:Real}(x::AbstractArray{T,2}, lo::Real, hi::Real) =
 
31
    [clamp(x[i,j], lo, hi) for i in 1:size(x,1), j in 1:size(x,2)]
 
32
clamp{T<:Real}(x::AbstractArray{T}, lo::Real, hi::Real) =
 
33
    reshape([clamp(xx, lo, hi) for xx in x], size(x))
29
34
 
30
35
sinc(x::Number) = x==0 ? one(x)  : (pix=pi*x; oftype(x,sin(pix)/pix))
31
36
cosc(x::Number) = x==0 ? zero(x) : (pix=pi*x; oftype(x,cos(pix)/x-sin(pix)/(pix*x)))
32
37
 
33
38
radians2degrees(z::Real) = oftype(z, (180/pi) * z)
34
39
degrees2radians(z::Real) = oftype(z, (pi/180) * z)
 
40
radians2degrees(z::Integer) = oftype(float(z), (180/pi) * z)
 
41
degrees2radians(z::Integer) = oftype(float(z), (pi/180) * z)
35
42
 
36
43
for (finv, f) in ((:sec, :cos), (:csc, :sin), (:cot, :tan),
37
44
                  (:sech, :cosh), (:csch, :sinh), (:coth, :tanh))
179
186
    function frexp(A::Array{Float64})
180
187
        f = similar(A)
181
188
        e = Array(Int, size(A))
182
 
        for i = 1:numel(A)
 
189
        for i = 1:length(A)
183
190
            f[i] = ccall((:frexp,libm), Float64, (Float64, Ptr{Int32}), A[i], exp)
184
191
            e[i] = exp[1]
185
192
        end
188
195
    function frexp(A::Array{Float32})
189
196
        f = similar(A)
190
197
        e = Array(Int, size(A))
191
 
        for i = 1:numel(A)
 
198
        for i = 1:length(A)
192
199
            f[i] = ccall((:frexpf,libm), Float32, (Float32, Ptr{Int32}), A[i], exp)
193
200
            e[i] = exp[1]
194
201
        end
660
667
end
661
668
@vectorize_1arg Number zeta
662
669
 
663
 
const Faddeeva_tmp = Array(Float64,2)
664
 
 
665
 
# wrappers for complex Faddeeva functions; these will get a lot simpler,
666
 
# and can call openopenlibm_extras directly, once ccall supports C99 complex types.
667
670
for f in (:erf, :erfc, :erfcx, :erfi, :Dawson)
668
671
    fname = (f === :Dawson) ? :dawson : f
669
672
    @eval begin
670
 
        function ($fname)(z::Complex128)
671
 
            ccall(($(string("wrapFaddeeva_",f)),:libFaddeeva_wrapper), Void, (Ptr{Complex128},Ptr{Complex128},Float64,), Faddeeva_tmp, &z, zero(Float64))
672
 
            return complex128(Faddeeva_tmp[1],Faddeeva_tmp[2])
673
 
        end
674
 
        function ($fname)(z::Complex64)
675
 
            ccall(($(string("wrapFaddeeva_",f)),:libFaddeeva_wrapper), Void, (Ptr{Complex128},Ptr{Complex128},Float64,), Faddeeva_tmp, &complex128(z), float64(eps(Float32)))
676
 
            return complex64(Faddeeva_tmp[1],Faddeeva_tmp[2])
677
 
        end
 
673
        ($fname)(z::Complex128) = complex128(ccall(($(string("Faddeeva_",f)),openlibm_extras), ComplexPair{Float64}, (ComplexPair{Float64}, Float64), z, zero(Float64)))
 
674
        ($fname)(z::Complex64) = complex64(ccall(($(string("Faddeeva_",f)),openlibm_extras), ComplexPair{Float64}, (ComplexPair{Float64}, Float64), complex128(z), float64(eps(Float32))))
678
675
        ($fname)(z::Complex) = ($fname)(complex128(z))
679
676
    end
680
677
end