typemax

typemax(T)

The highest value representable by the given (real) numeric DataType.

Examples

In the Julia programming language, the function typemax(T) is used to retrieve the highest value representable by the given (real) numeric DataType.

  1. Get the maximum value of an integer type:

    julia> typemax(Int)
    9223372036854775807

    This example returns the maximum representable value for the Int type.

  2. Find the maximum value for a floating-point type:

    julia> typemax(Float64)
    Inf

    It returns the highest value representable by the Float64 type, which is infinity.

  3. Retrieve the maximum value for a custom numeric type:

    julia> struct MyNumber
              value::Int
           end
    
    julia> typemax(MyNumber)
    MyNumber(9223372036854775807)

    This example demonstrates retrieving the maximum value for a custom numeric type MyNumber.

Common mistake example:

julia> typemax(Bool)
ERROR: TypeError: in typemax, expected Type{T}, got Bool

In this example, the typemax function is called with the Bool type, which is not a valid argument since it is not a real numeric type. Make sure to use typemax with real numeric types to avoid such errors.

See Also

BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: