Numbers
using AbstractTrees
AbstractTrees.children(t::Type) =
filter(t->isdefined(Base, Symbol(t)) || isdefined(Core, Symbol(t)), subtypes(t))
print_tree(Number)
Number
├─ Complex
└─ Real
├─ AbstractFloat
│ ├─ BigFloat
│ ├─ Float16
│ ├─ Float32
│ └─ Float64
├─ AbstractIrrational
│ └─ Irrational
├─ Integer
│ ├─ Bool
│ ├─ Signed
│ │ ├─ BigInt
│ │ ├─ Int128
│ │ ├─ Int16
│ │ ├─ Int32
│ │ ├─ Int64
│ │ └─ Int8
│ └─ Unsigned
│ ├─ UInt128
│ ├─ UInt16
│ ├─ UInt32
│ ├─ UInt64
│ └─ UInt8
└─ Rational
Core.Number
— TypeNumber
Abstract supertype for all number types.
Core.Real
— TypeReal <: Number
Abstract supertype for all real numbers.
Integer types
Core.Integer
— TypeInteger <: Real
Abstract supertype for all integers (e.g. Signed
, Unsigned
, and Bool
).
See also isinteger
, trunc
, div
.
Examples
julia> 42 isa Integer
true
julia> 1.0 isa Integer
false
julia> isinteger(1.0)
true
Core.Bool
— TypeBool <: Integer
Boolean type, containing the values true
and false
.
Bool
is a kind of number: false
is numerically equal to 0
and true
is numerically equal to 1
. Moreover, false
acts as a multiplicative "strong zero" against NaN
and Inf
:
julia> [true, false] == [1, 0]
true
julia> 42.0 + true
43.0
julia> 0 .* (NaN, Inf, -Inf)
(NaN, NaN, NaN)
julia> false .* (NaN, Inf, -Inf)
(0.0, 0.0, -0.0)
Branches via if
and other conditionals only accept Bool
. There are no "truthy" values in Julia.
Comparisons typically return Bool
, and broadcasted comparisons may return BitArray
instead of an Array{Bool}
.
julia> [1 2 3 4 5] .< pi
1×5 BitMatrix:
1 1 1 0 0
julia> map(>(pi), [1 2 3 4 5])
1×5 Matrix{Bool}:
0 0 0 1 1
Core.Unsigned
— TypeUnsigned <: Integer
Abstract supertype for all unsigned integers.
Built-in unsigned integers are printed in hexadecimal, with prefix 0x
, and can be entered in the same way.
Examples
julia> typemax(UInt8)
0xff
julia> Int(0x00d)
13
julia> unsigned(true)
0x0000000000000001
Core.UInt8
— TypeUInt8 <: Unsigned <: Integer
8-bit unsigned integer type.
Printed in hexadecimal, thus 0x07 == 7.
Core.UInt16
— TypeUInt16 <: Unsigned <: Integer
16-bit unsigned integer type.
Printed in hexadecimal, thus 0x000f == 15.
Core.UInt32
— TypeUInt32 <: Unsigned <: Integer
32-bit unsigned integer type.
Printed in hexadecimal, thus 0x0000001f == 31.
Core.UInt64
— TypeUInt64 <: Unsigned <: Integer
64-bit unsigned integer type.
Printed in hexadecimal, thus 0x000000000000003f == 63.
Core.UInt128
— TypeUInt128 <: Unsigned <: Integer
128-bit unsigned integer type.
Printed in hexadecimal, thus 0x0000000000000000000000000000007f == 127.
Core.Signed
— TypeSigned <: Integer
Abstract supertype for all signed integers.
Core.Int8
— TypeInt8 <: Signed <: Integer
8-bit signed integer type.
Represents numbers n ∈ -128:127
. Note that such integers overflow without warning, thus typemax(Int8) + Int8(1) < 0
.
Core.Int16
— TypeInt16 <: Signed <: Integer
16-bit signed integer type.
Represents numbers n ∈ -32768:32767
. Note that such integers overflow without warning, thus typemax(Int16) + Int16(1) < 0
.
Core.Int32
— TypeInt32 <: Signed <: Integer
32-bit signed integer type.
Note that such integers overflow without warning, thus typemax(Int32) + Int32(1) < 0
.
Core.Int64
— TypeInt64 <: Signed <: Integer
64-bit signed integer type.
Note that such integers overflow without warning, thus typemax(Int64) + Int64(1) < 0
.
Core.Int128
— TypeInt128 <: Signed <: Integer
128-bit signed integer type.
Note that such integers overflow without warning, thus typemax(Int128) + Int128(1) < 0
.
Base.GMP.BigInt
— TypeBigInt <: Signed
Arbitrary precision integer type.
Floating-point types
Core.AbstractFloat
— TypeAbstractFloat <: Real
Abstract supertype for all floating point numbers.
Core.Float16
— TypeFloat16 <: AbstractFloat <: Real
16-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 5 exponent, 10 fraction bits.
Core.Float32
— TypeFloat32 <: AbstractFloat <: Real
32-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 8 exponent, 23 fraction bits.
The exponent for scientific notation should be entered as lower-case f
, thus 2f3 === 2.0f0 * 10^3 === Float32(2_000)
. For array literals and comprehensions, the element type can be specified before the square brackets: Float32[1,4,9] == Float32[i^2 for i in 1:3]
.
Core.Float64
— TypeFloat64 <: AbstractFloat <: Real
64-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 11 exponent, 52 fraction bits. See bitstring
, signbit
, exponent
, frexp
, and significand
to access various bits.
This is the default for floating point literals, 1.0 isa Float64
, and for many operations such as 1/2, 2pi, log(2), range(0,90,length=4)
. Unlike integers, this default does not change with Sys.WORD_SIZE
.
The exponent for scientific notation can be entered as e
or E
, thus 2e3 === 2.0E3 === 2.0 * 10^3
. Doing so is strongly preferred over 10^n
because integers overflow, thus 2.0 * 10^19 < 0
but 2e19 > 0
.
Base.MPFR.BigFloat
— TypeBigFloat <: AbstractFloat
Arbitrary precision floating point number type.
Irrational
Base.AbstractIrrational
— TypeAbstractIrrational <: Real
Number type representing an exact irrational value, which is automatically rounded to the correct precision in arithmetic operations with other numeric quantities.
Subtypes MyIrrational <: AbstractIrrational
should implement at least ==(::MyIrrational, ::MyIrrational)
, hash(x::MyIrrational, h::UInt)
, and convert(::Type{F}, x::MyIrrational) where {F <: Union{BigFloat,Float32,Float64}}
.
If a subtype is used to represent values that may occasionally be rational (e.g. a square-root type that represents √n
for integers n
will give a rational result when n
is a perfect square), then it should also implement isinteger
, iszero
, isone
, and ==
with Real
values (since all of these default to false
for AbstractIrrational
types), as well as defining hash
to equal that of the corresponding Rational
.
Base.Irrational
— TypeIrrational{sym} <: AbstractIrrational
Number type representing an exact irrational value denoted by the symbol sym
, such as π
, ℯ
and γ
.
See also AbstractIrrational
.
Rational
Base.Rational
— TypeRational{T<:Integer} <: Real
Rational number type, with numerator and denominator of type T
. Rationals are checked for overflow.
Complex types
Base.Complex
— TypeComplex{T<:Real} <: Number
Complex number type with real and imaginary part of type T
.
ComplexF16
, ComplexF32
and ComplexF64
are aliases for Complex{Float16}
, Complex{Float32}
and Complex{Float64}
respectively.
Base.ComplexF16
— TypeComplex{T<:Real} <: Number
Complex number type with real and imaginary part of type T
.
ComplexF16
, ComplexF32
and ComplexF64
are aliases for Complex{Float16}
, Complex{Float32}
and Complex{Float64}
respectively.
Base.ComplexF32
— TypeComplex{T<:Real} <: Number
Complex number type with real and imaginary part of type T
.
ComplexF16
, ComplexF32
and ComplexF64
are aliases for Complex{Float16}
, Complex{Float32}
and Complex{Float64}
respectively.
Base.ComplexF64
— TypeComplex{T<:Real} <: Number
Complex number type with real and imaginary part of type T
.
ComplexF16
, ComplexF32
and ComplexF64
are aliases for Complex{Float16}
, Complex{Float32}
and Complex{Float64}
respectively.