Skip to content

Arguments typed as Number #38

@dmbates

Description

@dmbates

In many method definitions arguments are typed as Number. For example, in src/distrs/chisq.jl

# pdf for numbers with generic types
function chisqpdf(k::Real, x::Number)
  hk = k / 2  # half k
  1 / (2^(hk) * gamma(hk)) * x^(hk - 1) * exp(-x / 2)
end

# logpdf for numbers with generic types
function chisqlogpdf(k::Real, x::Number)
  hk = k / 2  # half k
  -hk * log(oftype(hk, 2)) - lgamma(hk) + (hk - 1) * log(x) - x / 2
end

It appears that the only difference between Number and Real is that Number includes Complex

julia> subtypes(Number)
2-element Array{Union{DataType, UnionAll},1}:
 Complex
 Real   

I don't see the purpose in allowing complex numbers in these cases. Any objection to my changing these to Real?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions