Numbers - Julia Documentation

The Julia Language logoThe Julia Language logoSearch docs (Ctrl + /)
  • Julia Documentation
  • Manual
    • Getting Started
    • Installation
    • Variables
    • Integers and Floating-Point Numbers
    • Mathematical Operations and Elementary Functions
    • Complex and Rational Numbers
    • Strings
    • Functions
    • Control Flow
    • Scope of Variables
    • Types
    • Methods
    • Constructors
    • Conversion and Promotion
    • Interfaces
    • Modules
    • Documentation
    • Metaprogramming
    • Single- and multi-dimensional Arrays
    • Missing Values
    • Networking and Streams
    • Parallel Computing
    • Asynchronous Programming
    • Multi-Threading
    • Multi-processing and Distributed Computing
    • Running External Programs
    • Calling C and Fortran Code
    • Handling Operating System Variation
    • Environment Variables
    • Embedding Julia
    • Code Loading
    • Profiling
    • Stack Traces
    • Memory Management and Garbage Collection
    • Performance Tips
    • Workflow Tips
    • Style Guide
    • Frequently Asked Questions
    • Noteworthy Differences from other Languages
    • Unicode Input
    • Command-line Interface
    • The World Age mechanism
  • Base
    • Essentials
    • Collections and Data Structures
    • Mathematics
    • Numbers
      • Standard Numeric Types
      • Data Formats
      • General Number Functions and Constants
      • BigFloats and BigInts
    • Strings
    • Arrays
    • Tasks
    • Multi-Threading
    • Scoped Values
    • Constants
    • Filesystem
    • I/O and Network
    • Punctuation
    • Sorting and Related Functions
    • Iteration utilities
    • Reflection and introspection
    • C Interface
    • C Standard Library
    • StackTraces
    • SIMD Support
  • Standard Library
    • ArgTools
    • Artifacts
    • Base64
    • CRC32c
    • Dates
    • Delimited Files
    • Distributed Computing
    • Downloads
    • Dynamic Linker
    • File Events
    • Future
    • Interactive Utilities
    • Julia Syntax Highlighting
    • Lazy Artifacts
    • LibCURL
    • LibGit2
    • Linear Algebra
    • Logging
    • Markdown
    • Memory-mapped I/O
    • Network Options
    • Pkg
    • Printf
    • Profiling
    • Random Numbers
    • The Julia REPL
    • Serialization
    • SHA
    • Shared Arrays
    • Sockets
    • Sparse Arrays
    • Statistics
    • StyledStrings
    • Tar
    • TOML
    • Unicode
    • Unit Testing
    • UUIDs
  • Developer Documentation
    • Documentation of Julia's Internals
      • Initialization of the Julia runtime
      • Julia ASTs
      • More about types
      • Memory layout of Julia Objects
      • Eval of Julia code
      • Calling Conventions
      • High-level Overview of the Native-Code Generation Process
      • Julia Functions
      • Base.Cartesian
      • Talking to the compiler (the :meta mechanism)
      • SubArrays
      • isbits Union Optimizations
      • System Image Building
      • Package Images
      • Custom LLVM Passes
      • Working with LLVM
      • printf() and stdio in the Julia runtime
      • Bounds checking
      • Proper maintenance and care of multi-threading locks
      • Arrays with custom indices
      • Module loading
      • Inference
      • Julia SSA-form IR
      • EscapeAnalysis
      • Ahead of Time Compilation
      • Static analyzer annotations for GC correctness in C code
      • Garbage Collection in Julia
      • JIT Design and Implementation
      • Core.Builtins
      • Fixing precompilation hangs due to open tasks or IO
    • Developing/debugging Julia's C code
      • Reporting and analyzing crashes (segfaults)
      • gdb debugging tips
      • Using Valgrind with Julia
      • External Profiler Support
      • Sanitizer support
      • Instrumenting Julia with DTrace, and bpftrace
    • Building Julia
      • Building Julia (Detailed)
      • Linux
      • macOS
      • Windows
      • FreeBSD
      • ARM (Linux)
      • RISC-V (Linux)
      • Binary distributions
VersionNumbers

Standard Numeric Types

A type tree for all subtypes of Number in Base is shown below. Abstract types have been marked, the rest are concrete types.

Number (Abstract Type) ├─ Complex └─ Real (Abstract Type) ├─ AbstractFloat (Abstract Type) │ ├─ Float16 │ ├─ Float32 │ ├─ Float64 │ └─ BigFloat ├─ Integer (Abstract Type) │ ├─ Bool │ ├─ Signed (Abstract Type) │ │ ├─ Int8 │ │ ├─ Int16 │ │ ├─ Int32 │ │ ├─ Int64 │ │ ├─ Int128 │ │ └─ BigInt │ └─ Unsigned (Abstract Type) │ ├─ UInt8 │ ├─ UInt16 │ ├─ UInt32 │ ├─ UInt64 │ └─ UInt128 ├─ Rational └─ AbstractIrrational (Abstract Type) └─ Irrational

Abstract number types

Core.Number — TypeNumber

Abstract supertype for all number types.

sourceCore.Real — TypeReal <: Number

Abstract supertype for all real numbers.

sourceCore.AbstractFloat — TypeAbstractFloat <: Real

Abstract supertype for all floating point numbers.

sourceCore.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) truesourceCore.Signed — TypeSigned <: Integer

Abstract supertype for all signed integers.

sourceCore.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) 0x0000000000000001sourceBase.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.

source

Concrete number types

Core.Float16 — TypeFloat16 <: AbstractFloat <: Real

16-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 5 exponent, 10 fraction bits.

sourceCore.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].

See also Inf32, NaN32, Float16, exponent, frexp.

sourceCore.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.

See also Inf, NaN, floatmax, Float32, Complex.

sourceBase.MPFR.BigFloat — TypeBigFloat <: AbstractFloat

Arbitrary precision floating point number type.

sourceCore.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

See also trues, falses, ifelse.

sourceCore.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.

See also Int, widen, BigInt.

sourceCore.UInt8 — TypeUInt8 <: Unsigned <: Integer

8-bit unsigned integer type.

Printed in hexadecimal, thus 0x07 == 7.

sourceCore.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.

See also Int, widen, BigInt.

sourceCore.UInt16 — TypeUInt16 <: Unsigned <: Integer

16-bit unsigned integer type.

Printed in hexadecimal, thus 0x000f == 15.

sourceCore.Int32 — TypeInt32 <: Signed <: Integer

32-bit signed integer type.

Note that such integers overflow without warning, thus typemax(Int32) + Int32(1) < 0.

See also Int, widen, BigInt.

sourceCore.UInt32 — TypeUInt32 <: Unsigned <: Integer

32-bit unsigned integer type.

Printed in hexadecimal, thus 0x0000001f == 31.

sourceCore.Int64 — TypeInt64 <: Signed <: Integer

64-bit signed integer type.

Note that such integers overflow without warning, thus typemax(Int64) + Int64(1) < 0.

See also Int, widen, BigInt.

sourceCore.UInt64 — TypeUInt64 <: Unsigned <: Integer

64-bit unsigned integer type.

Printed in hexadecimal, thus 0x000000000000003f == 63.

sourceCore.Int128 — TypeInt128 <: Signed <: Integer

128-bit signed integer type.

Note that such integers overflow without warning, thus typemax(Int128) + Int128(1) < 0.

See also Int, widen, BigInt.

sourceCore.UInt128 — TypeUInt128 <: Unsigned <: Integer

128-bit unsigned integer type.

Printed in hexadecimal, thus 0x0000000000000000000000000000007f == 127.

sourceCore.Int — TypeInt

Sys.WORD_SIZE-bit signed integer type, Int <: Signed <: Integer <: Real.

This is the default type of most integer literals and is an alias for either Int32 or Int64, depending on Sys.WORD_SIZE. It is the type returned by functions such as length, and the standard type for indexing arrays.

Note that integers overflow without warning, thus typemax(Int) + 1 < 0 and 10^19 < 0. Overflow can be avoided by using BigInt. Very large integer literals will use a wider type, for instance 10_000_000_000_000_000_000 isa Int128.

Integer division is div alias ÷, whereas / acting on integers returns Float64.

See also Int64, widen, typemax, bitstring.

sourceCore.UInt — TypeUInt

Sys.WORD_SIZE-bit unsigned integer type, UInt <: Unsigned <: Integer.

Like Int, the alias UInt may point to either UInt32 or UInt64, according to the value of Sys.WORD_SIZE on a given computer.

Printed and parsed in hexadecimal: UInt(15) === 0x000000000000000f.

sourceBase.GMP.BigInt — TypeBigInt <: Signed

Arbitrary precision integer type.

sourceBase.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.

See also: Real, complex, real.

sourceBase.Rational — TypeRational{T<:Integer} <: Real

Rational number type, with numerator and denominator of type T. Rationals are checked for overflow.

sourceBase.Irrational — TypeIrrational{sym} <: AbstractIrrational

Number type representing an exact irrational value denoted by the symbol sym, such as π, ℯ and γ.

See also AbstractIrrational.

source

Data Formats

Base.digits — Functiondigits([T<:Integer], n::Integer; base::T = 10, pad::Integer = 1)

Return an array with element type T (default Int) of the digits of n in the given base, optionally padded with zeros to a specified size. More significant digits are at higher indices, such that n == sum(digits[k]*base^(k-1) for k in 1:length(digits)).

See also ndigits, digits!, and for base 2 also bitstring, count_ones.

Examples

julia> digits(10) 2-element Vector{Int64}: 0 1 julia> digits(10, base = 2) 4-element Vector{Int64}: 0 1 0 1 julia> digits(-256, base = 10, pad = 5) 5-element Vector{Int64}: -6 -5 -2 0 0 julia> n = rand(-999:999); julia> n == evalpoly(13, digits(n, base = 13)) truesourceBase.digits! — Functiondigits!(array, n::Integer; base::Integer = 10)

Fills an array of the digits of n in the given base. More significant digits are at higher indices. If the array length is insufficient, the least significant digits are filled up to the array length. If the array length is excessive, the excess portion is filled with zeros.

Examples

julia> digits!([2, 2, 2, 2], 10, base = 2) 4-element Vector{Int64}: 0 1 0 1 julia> digits!([2, 2, 2, 2, 2, 2], 10, base = 2) 6-element Vector{Int64}: 0 1 0 1 0 0sourceBase.bitstring — Functionbitstring(n)

A string giving the literal bit representation of a primitive type (in bigendian order, i.e. most-significant bit first).

See also count_ones, count_zeros, digits.

Examples

julia> bitstring(Int32(4)) "00000000000000000000000000000100" julia> bitstring(2.2) "0100000000000001100110011001100110011001100110011001100110011010"sourceBase.parse — Functionparse(::Type{SimpleColor}, rgb::String)

An analogue of tryparse(SimpleColor, rgb::String) (which see), that raises an error instead of returning nothing.

parse(::Type{Platform}, triplet::AbstractString)

Parses a string platform triplet back into a Platform object.

sourceparse(type, str; base)

Parse a string as a number. For Integer types, a base can be specified (the default is 10). For floating-point types, the string is parsed as a decimal floating-point number. Complex types are parsed from decimal strings of the form "R±Iim" as a Complex(R,I) of the requested type; "i" or "j" can also be used instead of "im", and "R" or "Iim" are also permitted. If the string does not contain a valid number, an error is raised.

parse(Bool, str) requires at least Julia 1.1.

Examples

julia> parse(Int, "1234") 1234 julia> parse(Int, "1234", base = 5) 194 julia> parse(Int, "afc", base = 16) 2812 julia> parse(Float64, "1.2e-3") 0.0012 julia> parse(Complex{Float64}, "3.2e-1 + 4.5im") 0.32 + 4.5imsourceBase.tryparse — Functiontryparse(::Type{SimpleColor}, rgb::String)

Attempt to parse rgb as a SimpleColor. If rgb starts with # and has a length of 7, it is converted into a RGBTuple-backed SimpleColor. If rgb starts with a-z, rgb is interpreted as a color name and converted to a Symbol-backed SimpleColor.

Otherwise, nothing is returned.

Examples

julia> tryparse(SimpleColor, "blue") SimpleColor(blue) julia> tryparse(SimpleColor, "#9558b2") SimpleColor(#9558b2) julia> tryparse(SimpleColor, "#nocolor")tryparse(type, str; base)

Like parse, but returns either a value of the requested type, or nothing if the string does not contain a valid number.

sourceBase.big — Functionbig(x)

Convert a number to a maximum precision representation (typically BigInt or BigFloat). See BigFloat for information about some pitfalls with floating-point numbers.

sourceBase.signed — Functionsigned(x)

Convert a number to a signed integer. If the argument is unsigned, it is reinterpreted as signed without checking for overflow.

See also: unsigned, sign, signbit.

sourcesigned(T::Integer)

Convert an integer bitstype to the signed type of the same size.

Examples

julia> signed(UInt16) Int16 julia> signed(UInt64) Int64sourceBase.unsigned — Functionunsigned(T::Integer)

Convert an integer bitstype to the unsigned type of the same size.

Examples

julia> unsigned(Int16) UInt16 julia> unsigned(UInt64) UInt64sourceBase.float — Methodfloat(x)

Convert a number or array to a floating point data type.

See also: complex, oftype, convert.

Examples

julia> float(1:1000) 1.0:1.0:1000.0 julia> float(typemax(Int32)) 2.147483647e9sourceBase.Math.significand — Functionsignificand(x)

Extract the significand (a.k.a. mantissa) of a floating-point number. If x is a non-zero finite number, then the result will be a number of the same type and sign as x, and whose absolute value is on the interval $[1,2)$. Otherwise x is returned.

See also frexp, exponent.

Examples

julia> significand(15.2) 1.9 julia> significand(-15.2) -1.9 julia> significand(-15.2) * 2^3 -15.2 julia> significand(-Inf), significand(Inf), significand(NaN) (-Inf, Inf, NaN)sourceBase.Math.exponent — Functionexponent(x::Real) -> Int

Return the largest integer y such that 2^y ≤ abs(x). For a normalized floating-point number x, this corresponds to the exponent of x.

Throws a DomainError when x is zero, infinite, or NaN. For any other non-subnormal floating-point number x, this corresponds to the exponent bits of x.

See also signbit, significand, frexp, issubnormal, log2, ldexp.

Examples

julia> exponent(8) 3 julia> exponent(6.5) 2 julia> exponent(-1//4) -2 julia> exponent(3.142e-4) -12 julia> exponent(floatmin(Float32)), exponent(nextfloat(0.0f0)) (-126, -149) julia> exponent(0.0) ERROR: DomainError with 0.0: Cannot be ±0.0. [...]sourceBase.complex — Methodcomplex(r, [i])

Convert real numbers or arrays to complex. i defaults to zero.

Examples

julia> complex(7) 7 + 0im julia> complex([1, 2, 3]) 3-element Vector{Complex{Int64}}: 1 + 0im 2 + 0im 3 + 0imsourceBase.bswap — Functionbswap(n)

Reverse the byte order of n.

(See also ntoh and hton to convert between the current native byte order and big-endian order.)

Examples

julia> a = bswap(0x10203040) 0x40302010 julia> bswap(a) 0x10203040 julia> string(1, base = 2) "1" julia> string(bswap(1), base = 2) "100000000000000000000000000000000000000000000000000000000"sourceBase.hex2bytes — Functionhex2bytes(itr)

Given an iterable itr of ASCII codes for a sequence of hexadecimal digits, returns a Vector{UInt8} of bytes corresponding to the binary representation: each successive pair of hexadecimal digits in itr gives the value of one byte in the return vector.

The length of itr must be even, and the returned array has half of the length of itr. See also hex2bytes! for an in-place version, and bytes2hex for the inverse.

Calling hex2bytes with iterators producing UInt8 values requires Julia 1.7 or later. In earlier versions, you can collect the iterator before calling hex2bytes.

Examples

julia> s = string(12345, base = 16) "3039" julia> hex2bytes(s) 2-element Vector{UInt8}: 0x30 0x39 julia> a = b"01abEF" 6-element Base.CodeUnits{UInt8, String}: 0x30 0x31 0x61 0x62 0x45 0x46 julia> hex2bytes(a) 3-element Vector{UInt8}: 0x01 0xab 0xefsourceBase.hex2bytes! — Functionhex2bytes!(dest::AbstractVector{UInt8}, itr)

Convert an iterable itr of bytes representing a hexadecimal string to its binary representation, similar to hex2bytes except that the output is written in-place to dest. The length of dest must be half the length of itr.

Calling hex2bytes! with iterators producing UInt8 requires version 1.7. In earlier versions, you can collect the iterable before calling instead.

sourceBase.bytes2hex — Functionbytes2hex(itr) -> String bytes2hex(io::IO, itr)

Convert an iterator itr of bytes to its hexadecimal string representation, either returning a String via bytes2hex(itr) or writing the string to an io stream via bytes2hex(io, itr). The hexadecimal characters are all lowercase.

Calling bytes2hex with arbitrary iterators producing UInt8 values requires Julia 1.7 or later. In earlier versions, you can collect the iterator before calling bytes2hex.

Examples

julia> a = string(12345, base = 16) "3039" julia> b = hex2bytes(a) 2-element Vector{UInt8}: 0x30 0x39 julia> bytes2hex(b) "3039"source

General Number Functions and Constants

Base.one — Functionone(x) one(T::Type)

Return a multiplicative identity for x: a value such that one(x)*x == x*one(x) == x. If the multiplicative identity can be deduced from the type alone, then a type may be given as an argument to one (e.g. one(Int) will work because the multiplicative identity is the same for all instances of Int, but one(Matrix{Int}) is not defined because matrices of different shapes have different multiplicative identities.)

If possible, one(x) returns a value of the same type as x, and one(T) returns a value of type T. However, this may not be the case for types representing dimensionful quantities (e.g. time in days), since the multiplicative identity must be dimensionless. In that case, one(x) should return an identity value of the same precision (and shape, for matrices) as x.

If you want a quantity that is of the same type as x, or of type T, even if x is dimensionful, use oneunit instead.

See also the identity function, and I in LinearAlgebra for the identity matrix.

Examples

julia> one(3.7) 1.0 julia> one(Int) 1 julia> import Dates; one(Dates.Day(1)) 1sourceBase.oneunit — Functiononeunit(x::T) oneunit(T::Type)

Return T(one(x)), where T is either the type of the argument, or the argument itself in cases where the oneunit can be deduced from the type alone. This differs from one for dimensionful quantities: one is dimensionless (a multiplicative identity) while oneunit is dimensionful (of the same type as x, or of type T).

Examples

julia> oneunit(3.7) 1.0 julia> import Dates; oneunit(Dates.Day) 1 daysourceBase.zero — Functionzero(x) zero(::Type)

Get the additive identity element for x. If the additive identity can be deduced from the type alone, then a type may be given as an argument to zero.

For example, zero(Int) will work because the additive identity is the same for all instances of Int, but zero(Vector{Int}) is not defined because vectors of different lengths have different additive identities.

See also iszero, one, oneunit, oftype.

Examples

julia> zero(1) 0 julia> zero(big"2.0") 0.0 julia> zero(rand(2,2)) 2×2 Matrix{Float64}: 0.0 0.0 0.0 0.0sourceBase.im — Constantim

The imaginary unit.

See also: imag, angle, complex.

Examples

julia> im * im -1 + 0im julia> (2.0 + 3im)^2 -5.0 + 12.0imsourceBase.MathConstants.pi — Constantπ pi

The constant pi.

Unicode π can be typed by writing \pi then pressing tab in the Julia REPL, and in many editors.

See also: sinpi, sincospi, deg2rad.

Examples

julia> pi π = 3.1415926535897... julia> 1/2pi 0.15915494309189535sourceBase.MathConstants.ℯ — Constantℯ e

The constant ℯ.

Unicode ℯ can be typed by writing \euler and pressing tab in the Julia REPL, and in many editors.

See also: exp, cis, cispi.

Examples

julia> ℯ ℯ = 2.7182818284590... julia> log(ℯ) 1 julia> ℯ^(im)π ≈ -1 truesourceBase.MathConstants.catalan — Constantcatalan

Catalan's constant.

Examples

julia> Base.MathConstants.catalan catalan = 0.9159655941772... julia> sum(log(x)/(1+x^2) for x in 1:0.01:10^6) * 0.01 0.9159466120554123sourceBase.MathConstants.eulergamma — Constantγ eulergamma

Euler's constant.

Examples

julia> Base.MathConstants.eulergamma γ = 0.5772156649015... julia> dx = 10^-6; julia> sum(-exp(-x) * log(x) for x in dx:dx:100) * dx 0.5772078382499133sourceBase.MathConstants.golden — Constantφ golden

The golden ratio.

Examples

julia> Base.MathConstants.golden φ = 1.6180339887498... julia> (2ans - 1)^2 ≈ 5 truesourceBase.Inf — ConstantInf, Inf64

Positive infinity of type Float64.

See also: isfinite, typemax, NaN, Inf32.

Examples

julia> π/0 Inf julia> +1.0 / -0.0 -Inf julia> ℯ^-Inf 0.0sourceBase.Inf64 — ConstantInf, Inf64

Positive infinity of type Float64.

See also: isfinite, typemax, NaN, Inf32.

Examples

julia> π/0 Inf julia> +1.0 / -0.0 -Inf julia> ℯ^-Inf 0.0sourceBase.Inf32 — ConstantInf32

Positive infinity of type Float32.

sourceBase.Inf16 — ConstantInf16

Positive infinity of type Float16.

sourceBase.NaN — ConstantNaN, NaN64

A not-a-number value of type Float64.

See also: isnan, missing, NaN32, Inf.

Examples

julia> 0/0 NaN julia> Inf - Inf NaN julia> NaN == NaN, isequal(NaN, NaN), isnan(NaN) (false, true, true)

Always use isnan or isequal for checking for NaN. Using x === NaN may give unexpected results:

julia> reinterpret(UInt32, NaN32) 0x7fc00000 julia> NaN32p1 = reinterpret(Float32, 0x7fc00001) NaN32 julia> NaN32p1 === NaN32, isequal(NaN32p1, NaN32), isnan(NaN32p1) (false, true, true)sourceBase.NaN64 — ConstantNaN, NaN64

A not-a-number value of type Float64.

See also: isnan, missing, NaN32, Inf.

Examples

julia> 0/0 NaN julia> Inf - Inf NaN julia> NaN == NaN, isequal(NaN, NaN), isnan(NaN) (false, true, true)

Always use isnan or isequal for checking for NaN. Using x === NaN may give unexpected results:

julia> reinterpret(UInt32, NaN32) 0x7fc00000 julia> NaN32p1 = reinterpret(Float32, 0x7fc00001) NaN32 julia> NaN32p1 === NaN32, isequal(NaN32p1, NaN32), isnan(NaN32p1) (false, true, true)sourceBase.NaN32 — ConstantNaN32

A not-a-number value of type Float32.

See also: NaN.

sourceBase.NaN16 — ConstantNaN16

A not-a-number value of type Float16.

See also: NaN.

sourceBase.issubnormal — Functionissubnormal(f) -> Bool

Test whether a floating point number is subnormal.

An IEEE floating point number is subnormal when its exponent bits are zero and its significand is not zero.

Examples

julia> floatmin(Float32) 1.1754944f-38 julia> issubnormal(1.0f-37) false julia> issubnormal(1.0f-38) truesourceBase.isfinite — Functionisfinite(f) -> Bool

Test whether a number is finite.

Examples

julia> isfinite(5) true julia> isfinite(NaN32) falsesourceBase.isinf — Functionisinf(f) -> Bool

Test whether a number is infinite.

See also: Inf, iszero, isfinite, isnan.

sourceBase.isnan — Functionisnan(f) -> Bool

Test whether a number value is a NaN, an indeterminate value which is neither an infinity nor a finite number ("not a number").

See also: iszero, isone, isinf, ismissing.

sourceBase.iszero — Functioniszero(x)

Return true if x == zero(x); if x is an array, this checks whether all of the elements of x are zero.

See also: isone, isinteger, isfinite, isnan.

Examples

julia> iszero(0.0) true julia> iszero([1, 9, 0]) false julia> iszero([false, 0, 0]) truesourceBase.isone — Functionisone(x)

Return true if x == one(x); if x is an array, this checks whether x is an identity matrix.

Examples

julia> isone(1.0) true julia> isone([1 0; 0 2]) false julia> isone([1 0; 0 true]) truesourceBase.nextfloat — Functionnextfloat(x::AbstractFloat)

Return the smallest floating point number y of the same type as x such that x < y. If no such y exists (e.g. if x is Inf or NaN), then return x.

See also: prevfloat, eps, issubnormal.

sourcenextfloat(x::AbstractFloat, n::Integer)

The result of n iterative applications of nextfloat to x if n >= 0, or -n applications of prevfloat if n < 0.

sourceBase.prevfloat — Functionprevfloat(x::AbstractFloat)

Return the largest floating point number y of the same type as x such that y < x. If no such y exists (e.g. if x is -Inf or NaN), then return x.

sourceprevfloat(x::AbstractFloat, n::Integer)

The result of n iterative applications of prevfloat to x if n >= 0, or -n applications of nextfloat if n < 0.

sourceBase.isinteger — Functionisinteger(x) -> Bool

Test whether x is numerically equal to some integer.

Examples

julia> isinteger(4.0) truesourceBase.isreal — Functionisreal(x) -> Bool

Test whether x or all its elements are numerically equal to some real number including infinities and NaNs. isreal(x) is true if isequal(x, real(x)) is true.

Examples

julia> isreal(5.) true julia> isreal(1 - 3im) false julia> isreal(Inf + 0im) true julia> isreal([4.; complex(0,1)]) falsesourceCore.Float32 — MethodFloat32(x [, mode::RoundingMode])

Create a Float32 from x. If x is not exactly representable then mode determines how x is rounded.

Examples

julia> Float32(1/3, RoundDown) 0.3333333f0 julia> Float32(1/3, RoundUp) 0.33333334f0

See RoundingMode for available rounding modes.

sourceCore.Float64 — MethodFloat64(x [, mode::RoundingMode])

Create a Float64 from x. If x is not exactly representable then mode determines how x is rounded.

Examples

julia> Float64(pi, RoundDown) 3.141592653589793 julia> Float64(pi, RoundUp) 3.1415926535897936

See RoundingMode for available rounding modes.

sourceBase.Rounding.rounding — Functionrounding(T)

Get the current floating point rounding mode for type T, controlling the rounding of basic arithmetic functions (+, -, *, / and sqrt) and type conversion.

See RoundingMode for available modes.

sourceBase.Rounding.setrounding — Methodsetrounding(T, mode)

Set the rounding mode of floating point type T, controlling the rounding of basic arithmetic functions (+, -, *, / and sqrt) and type conversion. Other numerical functions may give incorrect or invalid values when using rounding modes other than the default RoundNearest.

Note that this is currently only supported for T == BigFloat.

This function is not thread-safe. It will affect code running on all threads, but its behavior is undefined if called concurrently with computations that use the setting.

sourceBase.Rounding.setrounding — Methodsetrounding(f::Function, T, mode)

Change the rounding mode of floating point type T for the duration of f. It is logically equivalent to:

old = rounding(T) setrounding(T, mode) f() setrounding(T, old)

See RoundingMode for available rounding modes.

sourceBase.Rounding.get_zero_subnormals — Functionget_zero_subnormals() -> Bool

Return false if operations on subnormal floating-point values ("denormals") obey rules for IEEE arithmetic, and true if they might be converted to zeros.

This function only affects the current thread.

sourceBase.Rounding.set_zero_subnormals — Functionset_zero_subnormals(yes::Bool) -> Bool

If yes is false, subsequent floating-point operations follow rules for IEEE arithmetic on subnormal values ("denormals"). Otherwise, floating-point operations are permitted (but not required) to convert subnormal inputs or outputs to zero. Returns true unless yes==true but the hardware does not support zeroing of subnormal numbers.

set_zero_subnormals(true) can speed up some computations on some hardware. However, it can break identities such as (x-y==0) == (x==y).

This function only affects the current thread.

source

Integers

Base.count_ones — Functioncount_ones(x::Integer) -> Integer

Number of ones in the binary representation of x.

Examples

julia> count_ones(7) 3 julia> count_ones(Int32(-1)) 32sourceBase.count_zeros — Functioncount_zeros(x::Integer) -> Integer

Number of zeros in the binary representation of x.

Examples

julia> count_zeros(Int32(2 ^ 16 - 1)) 16 julia> count_zeros(-1) 0sourceBase.leading_zeros — Functionleading_zeros(x::Integer) -> Integer

Number of zeros leading the binary representation of x.

Examples

julia> leading_zeros(Int32(1)) 31sourceBase.leading_ones — Functionleading_ones(x::Integer) -> Integer

Number of ones leading the binary representation of x.

Examples

julia> leading_ones(UInt32(2 ^ 32 - 2)) 31sourceBase.trailing_zeros — Functiontrailing_zeros(x::Integer) -> Integer

Number of zeros trailing the binary representation of x.

Examples

julia> trailing_zeros(2) 1sourceBase.trailing_ones — Functiontrailing_ones(x::Integer) -> Integer

Number of ones trailing the binary representation of x.

Examples

julia> trailing_ones(3) 2sourceBase.isodd — Functionisodd(x::Number) -> Bool

Return true if x is an odd integer (that is, an integer not divisible by 2), and false otherwise.

Non-Integer arguments require Julia 1.7 or later.

Examples

julia> isodd(9) true julia> isodd(10) falsesourceBase.iseven — Functioniseven(x::Number) -> Bool

Return true if x is an even integer (that is, an integer divisible by 2), and false otherwise.

Non-Integer arguments require Julia 1.7 or later.

Examples

julia> iseven(9) false julia> iseven(10) truesourceCore.@int128_str — Macro@int128_str str

Parse str as an Int128. Throw an ArgumentError if the string is not a valid integer.

Examples

julia> int128"123456789123" 123456789123 julia> int128"123456789123.4" ERROR: LoadError: ArgumentError: invalid base 10 digit '.' in "123456789123.4" [...]sourceCore.@uint128_str — Macro@uint128_str str

Parse str as an UInt128. Throw an ArgumentError if the string is not a valid integer.

Examples

julia> uint128"123456789123" 0x00000000000000000000001cbe991a83 julia> uint128"-123456789123" ERROR: LoadError: ArgumentError: invalid base 10 digit '-' in "-123456789123" [...]source

BigFloats and BigInts

The BigFloat and BigInt types implements arbitrary-precision floating point and integer arithmetic, respectively. For BigFloat the GNU MPFR library is used, and for BigInt the [GNU Multiple Precision Arithmetic Library (GMP)] (https://gmplib.org) is used.

Base.MPFR.BigFloat — MethodBigFloat(x::Union{Real, AbstractString} [, rounding::RoundingMode=rounding(BigFloat)]; [precision::Integer=precision(BigFloat)])

Create an arbitrary precision floating point number from x, with precision precision. The rounding argument specifies the direction in which the result should be rounded if the conversion cannot be done exactly. If not provided, these are set by the current global values.

BigFloat(x::Real) is the same as convert(BigFloat,x), except if x itself is already BigFloat, in which case it will return a value with the precision set to the current global precision; convert will always return x.

BigFloat(x::AbstractString) is identical to parse. This is provided for convenience since decimal literals are converted to Float64 when parsed, so BigFloat(2.1) may not yield what you expect.

See also:

  • @big_str
  • rounding and setrounding
  • precision and setprecision

precision as a keyword argument requires at least Julia 1.1. In Julia 1.0 precision is the second positional argument (BigFloat(x, precision)).

Examples

julia> BigFloat(2.1) # 2.1 here is a Float64 2.100000000000000088817841970012523233890533447265625 julia> BigFloat("2.1") # the closest BigFloat to 2.1 2.099999999999999999999999999999999999999999999999999999999999999999999999999986 julia> BigFloat("2.1", RoundUp) 2.100000000000000000000000000000000000000000000000000000000000000000000000000021 julia> BigFloat("2.1", RoundUp, precision=128) 2.100000000000000000000000000000000000007sourceBase.precision — Functionprecision(num::AbstractFloat; base::Integer=2) precision(T::Type; base::Integer=2)

Get the precision of a floating point number, as defined by the effective number of bits in the significand, or the precision of a floating-point type T (its current default, if T is a variable-precision type like BigFloat).

If base is specified, then it returns the maximum corresponding number of significand digits in that base.

The base keyword requires at least Julia 1.8.

sourceBase.MPFR.setprecision — Functionsetprecision(f::Function, [T=BigFloat,] precision::Integer; base=2)

Change the T arithmetic precision (in the given base) for the duration of f. It is logically equivalent to:

old = precision(BigFloat) setprecision(BigFloat, precision) f() setprecision(BigFloat, old)

Often used as setprecision(T, precision) do ... end

Note: nextfloat(), prevfloat() do not use the precision mentioned by setprecision.

There is a fallback implementation of this method that calls precision and setprecision, but it should no longer be relied on. Instead, you should define the 3-argument form directly in a way that uses ScopedValue, or recommend that callers use ScopedValue and @with themselves.

The base keyword requires at least Julia 1.8.

sourcesetprecision([T=BigFloat,] precision::Int; base=2)

Set the precision (in bits, by default) to be used for T arithmetic. If base is specified, then the precision is the minimum required to give at least precision digits in the given base.

This function is not thread-safe. It will affect code running on all threads, but its behavior is undefined if called concurrently with computations that use the setting.

The base keyword requires at least Julia 1.8.

sourceBase.GMP.BigInt — MethodBigInt(x)

Create an arbitrary precision integer. x may be an Int (or anything that can be converted to an Int). The usual mathematical operators are defined for this type, and results are promoted to a BigInt.

Instances can be constructed from strings via parse, or using the big string literal.

Examples

julia> parse(BigInt, "42") 42 julia> big"313" 313 julia> BigInt(10)^19 10000000000000000000sourceCore.@big_str — Macro@big_str str

Parse a string into a BigInt or BigFloat, and throw an ArgumentError if the string is not a valid number. For integers _ is allowed in the string as a separator.

Examples

julia> big"123_456" 123456 julia> big"7891.5" 7891.5 julia> big"_" ERROR: ArgumentError: invalid number format _ for BigInt or BigFloat [...]

Using @big_str for constructing BigFloat values may not result in the behavior that might be naively expected: as a macro, @big_str obeys the global precision (setprecision) and rounding mode (setrounding) settings as they are at load time. Thus, a function like () -> precision(big"0.3") returns a constant whose value depends on the value of the precision at the point when the function is defined, not at the precision at the time when the function is called.

source« MathematicsStrings »

Powered by Documenter.jl and the Julia Programming Language.

ThemeAutomatic (OS)documenter-lightdocumenter-darkcatppuccin-lattecatppuccin-frappecatppuccin-macchiatocatppuccin-mocha

This document was generated with Documenter.jl version 1.16.1 on Monday 15 December 2025. Using Julia version 1.12.3.

Tag » What Is Julia's Phone Number