diff --git a/docs/make.jl b/docs/make.jl index 5e56fe9..313d696 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -24,7 +24,8 @@ makedocs(; sitename="ReachabilityBase.jl", "Subtypes" => "lib/Subtypes.md", "Arrays" => "lib/Arrays.md", "Timing" => "lib/Timing.md", - "CurrentPath" => "lib/CurrentPath.md" + "CurrentPath" => "lib/CurrentPath.md", + "Basetype" => "lib/Basetype.md" # ], "About" => "about.md"], diff --git a/docs/src/lib/Basetype.md b/docs/src/lib/Basetype.md new file mode 100644 index 0000000..68ce2c6 --- /dev/null +++ b/docs/src/lib/Basetype.md @@ -0,0 +1,17 @@ +# Basetype + +This section of the manual describes the `Basetype` module. + +```@contents +Pages = ["Basetype.md"] +Depth = 3 +``` + +```@meta +CurrentModule = ReachabilityBase.Basetype +``` + +```@docs +Basetype +basetype +``` diff --git a/src/Basetype/Basetype.jl b/src/Basetype/Basetype.jl new file mode 100644 index 0000000..86e2610 --- /dev/null +++ b/src/Basetype/Basetype.jl @@ -0,0 +1,62 @@ +""" + Basetype + +This module provides the functionality to obtain the base type of a type or object. +""" +module Basetype + +export basetype + +""" + basetype(T::Type) + +Return the base type of the given type (i.e., without type parameters). + +### Input + +- `T` -- type + +### Output + +The base type of `T`. + +```jldoctest +julia> using ReachabilityBase.Basetype + +julia> basetype(Float64) +Float64 + +julia> basetype(Rational{Int}) +Rational +``` +""" +basetype(T::Type) = Base.typename(T).wrapper + +""" + basetype(x) + +Return the base type of the given object (i.e., without type parameters). + +### Input + +- `x` -- object + +### Output + +The base type of `x`. + +### Examples + +```jldoctest +julia> using ReachabilityBase.Basetype + +julia> basetype(1.0) +Float64 + +julia> basetype(1//1) +Rational +``` +""" +basetype(x) = basetype(typeof(x)) + +end # module diff --git a/src/ReachabilityBase.jl b/src/ReachabilityBase.jl index 0dcd54e..a32e7ae 100644 --- a/src/ReachabilityBase.jl +++ b/src/ReachabilityBase.jl @@ -10,5 +10,6 @@ include("Subtypes/Subtypes.jl") include("Arrays/Arrays.jl") include("Timing/Timing.jl") include("CurrentPath/CurrentPath.jl") +include("Basetype/Basetype.jl") end # module