## [Mathematical Functions](#Mathematical-Functions)
See also: [`angle`](#Base.angle), [`adjoint`](../../stdlib/LinearAlgebra/#Base.adjoint).
**Examples**
```julia-repl
julia> conj(1 + 3im)
1 - 3im
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L272-L284)
```julia
conj(A::AbstractArray)
```
Return an array containing the complex conjugate of each entry in array `A`.
Equivalent to `conj.(A)`, except that when `eltype(A) <: Real` `A` is returned without copying, and that when `A` has zero dimensions, a 0-dimensional array is returned (rather than a scalar).
**Examples**
```julia-repl
julia> conj([1, 2im, 3 + 4im])
3-element Vector{Complex{Int64}}:
 1 + 0im
 0 - 2im
 3 - 4im

julia> conj(fill(2 - im))
0-dimensional Array{Complex{Int64}, 0}:
2 + 1im
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/abstractarraymath.jl#L124-L145)
```julia
angle(z)
```
Compute the phase angle in radians of a complex number `z`.
Returns a number `-pi ≤ angle(z) ≤ pi`, and is thus discontinuous along the negative real axis.
See also: [`atan`](#Base.atan-Tuple%7BNumber%7D), [`cis`](#Base.cis), [`rad2deg`](#Base.Math.rad2deg).
**Examples**
```julia-repl
julia> rad2deg(angle(1 + im))
45.0

julia> rad2deg(angle(1 - im))
-45.0

julia> rad2deg(angle(-1 + 1e-20im))
180.0

julia> rad2deg(angle(-1 - 1e-20im))
-180.0
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L623-L647)
```julia
cis(x)
```


## [Mathematical Functions](#Mathematical-Functions)
More efficient method for `exp(im*x)` by using Euler's formula: $\\cos(x) + i \\sin(x) = \\exp(i x)$.
See also [`cispi`](#Base.cispi), [`sincos`](#Base.Math.sincos-Tuple%7BFloat64%7D), [`exp`](#Base.exp-Tuple%7BFloat64%7D), [`angle`](#Base.angle).
**Examples**
```julia-repl
julia> cis(π) ≈ -1
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L570-L582)
```julia
cispi(x)
```
More accurate method for `cis(pi*x)` (especially for large `x`).
See also [`cis`](#Base.cis), [`sincospi`](#Base.Math.sincospi), [`exp`](#Base.exp-Tuple%7BFloat64%7D), [`angle`](#Base.angle).
**Examples**
```julia-repl
julia> cispi(10000)
1.0 + 0.0im

julia> cispi(0.25 + 1im)
0.030556854645954562 + 0.03055685464595456im
```
This function requires Julia 1.6 or later.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L595-L613)
```julia
binomial(n::Integer, k::Integer)
```
The *binomial coefficient* $\\binom{n}{k}$, being the coefficient of the $k$th term in the polynomial expansion of $(1+x)^n$.
If $n$ is non-negative, then it is the number of ways to choose `k` out of `n` items:
\\\[\\binom{n}{k} = \\frac{n!}{k! (n-k)!}\\\]
where $n!$ is the [`factorial`](#Base.factorial) function.
If $n$ is negative, then it is defined in terms of the identity
\\\[\\binom{n}{k} = (-1)^k \\binom{k-n-1}{k}\\\]
See also [`factorial`](#Base.factorial).
**Examples**


## [Mathematical Functions](#Mathematical-Functions)
```julia-repl
julia> binomial(5, 3)
10

julia> factorial(5) ÷ (factorial(5-3) * factorial(3))
10

julia> binomial(-5, 3)
-35
```
**External links**
-   [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient) on Wikipedia.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L1146-L1179)
```julia
binomial(x::Number, k::Integer)
```
The generalized binomial coefficient, defined for `k ≥ 0` by the polynomial
\\\[\\frac{1}{k!} \\prod\_{j=0}^{k-1} (x - j)\\\]
When `k < 0` it returns zero.
For the case of integer `x`, this is equivalent to the ordinary integer binomial coefficient
\\\[\\binom{n}{k} = \\frac{n!}{k! (n-k)!}\\\]
Further generalizations to non-integer `k` are mathematically possible, but involve the Gamma function and/or the beta function, which are not provided by the Julia standard library but are available in external packages such as [SpecialFunctions.jl](https://github.com/JuliaMath/SpecialFunctions.jl).
**External links**
-   [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient) on Wikipedia.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L1209-L1232)
```julia
factorial(n::Integer)
```


## [Mathematical Functions](#Mathematical-Functions)
Factorial of `n`. If `n` is an [`Integer`](../numbers/#Core.Integer), the factorial is computed as an integer (promoted to at least 64 bits). Note that this may overflow if `n` is not small, but you can use `factorial(big(n))` to compute the result exactly in arbitrary precision.
See also [`binomial`](#Base.binomial).
**Examples**
```julia-repl
julia> factorial(6)
720

julia> factorial(21)
ERROR: OverflowError: 21 is too large to look up in the table; consider using `factorial(big(21))` instead
Stacktrace:
[...]

julia> factorial(big(21))
51090942171709440000
```
**External links**
-   [Factorial](https://en.wikipedia.org/wiki/Factorial) on Wikipedia.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L1111-L1136)
```julia
gcd(x, y...)
```
Greatest common (positive) divisor (or zero if all arguments are zero). The arguments may be integer and rational numbers.
Rational arguments require Julia 1.4 or later.
**Examples**
```julia-repl
julia> gcd(6, 9)
3

julia> gcd(6, -9)
3

julia> gcd(6, 0)
6

julia> gcd(0, 0)
0

julia> gcd(1//3, 2//3)
1//3

julia> gcd(1//3, -2//3)
1//3

julia> gcd(1//3, 2)
1//3

julia> gcd(0, 0, 10, 15)
5
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L5-L40)
```julia
lcm(x, y...)
```
Least common (positive) multiple (or zero if any argument is zero). The arguments may be integer and rational numbers.
Rational arguments require Julia 1.4 or later.
**Examples**


## [Mathematical Functions](#Mathematical-Functions)
```julia-repl
julia> lcm(2, 3)
6

julia> lcm(-2, 3)
6

julia> lcm(0, 3)
0

julia> lcm(0, 0)
0

julia> lcm(1//3, 2//3)
2//3

julia> lcm(1//3, -2//3)
2//3

julia> lcm(1//3, 2)
2//1

julia> lcm(1, 3, 5, 7)
105
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L94-L129)
```julia
gcdx(a, b)
```
Computes the greatest common (positive) divisor of `a` and `b` and their Bézout coefficients, i.e. the integer coefficients `u` and `v` that satisfy $ua+vb = d = gcd(a, b)$. $gcdx(a, b)$ returns $(d, u, v)$.
The arguments may be integer and rational numbers.
Rational arguments require Julia 1.4 or later.
**Examples**
```julia-repl
julia> gcdx(12, 42)
(6, -3, 1)

julia> gcdx(240, 46)
(2, -9, 47)
```
Bézout coefficients are *not* uniquely defined. `gcdx` returns the minimal Bézout coefficients that are computed by the extended Euclidean algorithm. (Ref: D. Knuth, TAoCP, 2/e, p. 325, Algorithm X.) For signed integers, these coefficients `u` and `v` are minimal in the sense that $\|u\| \< \|b/d\|$ and $\|v\| \< \|a/d\|$. Furthermore, the signs of `u` and `v` are chosen so that `d` is positive. For unsigned integers, the coefficients `u` and `v` might be near their `typemax`, and the identity then holds only via the unsigned integers' modulo arithmetic.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L167-L198)
```julia
ispow2(n::Number) -> Bool
```
Test whether `n` is an integer power of two.


## [Mathematical Functions](#Mathematical-Functions)
See also [`count_ones`](../numbers/#Base.count_ones), [`prevpow`](#Base.prevpow), [`nextpow`](#Base.nextpow).
**Examples**
```julia-repl
julia> ispow2(4)
true

julia> ispow2(5)
false

julia> ispow2(4.5)
false

julia> ispow2(0.25)
true

julia> ispow2(1//8)
true
```
Support for non-`Integer` arguments was added in Julia 1.6.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L463-L490)
```julia
nextpow(a, x)
```
The smallest `a^n` not less than `x`, where `n` is a non-negative integer. `a` must be greater than 1, and `x` must be greater than 0.
See also [`prevpow`](#Base.prevpow).
**Examples**
```julia-repl
julia> nextpow(2, 7)
8

julia> nextpow(2, 9)
16

julia> nextpow(5, 20)
25

julia> nextpow(4, 16)
16
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L495-L517)
```julia
prevpow(a, x)
```
The largest `a^n` not greater than `x`, where `n` is a non-negative integer. `a` must be greater than 1, and `x` must not be less than 1.
See also [`nextpow`](#Base.nextpow), [`isqrt`](#Base.isqrt).
**Examples**
```julia-repl
julia> prevpow(2, 7)
4

julia> prevpow(2, 9)
8

julia> prevpow(5, 20)
5

julia> prevpow(4, 16)
16
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L540-L562)
```julia
nextprod(factors::Union{Tuple,AbstractVector}, n)
```


## [Mathematical Functions](#Mathematical-Functions)
Next integer greater than or equal to `n` that can be written as $\\prod k_i^{p_i}$ for integers $p_1$, $p_2$, etcetera, for factors $k_i$ in `factors`.
**Examples**
```julia-repl
julia> nextprod((2, 3), 105)
108

julia> 2^2 * 3^3
108
```
The method that accepts a tuple requires Julia 1.6 or later.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/combinatorics.jl#L313-L330)
```julia
invmod(n::Integer, m::Integer)
```
Take the inverse of `n` modulo `m`: `y` such that $n y = 1 \\pmod m$, and $div(y,m) = 0$. This will throw an error if $m = 0$, or if $gcd(n,m) \\neq 1$.
**Examples**
```julia-repl
julia> invmod(2, 5)
3

julia> invmod(2, 3)
2

julia> invmod(5, 6)
5
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L220-L238)
```julia
invmod(n::Integer, T) where {T <: Base.BitInteger}
invmod(n::T) where {T <: Base.BitInteger}
```
Compute the modular inverse of `n` in the integer ring of type `T`, i.e. modulo `2^N` where `N = 8*sizeof(T)` (e.g. `N = 32` for `Int32`). In other words these methods satisfy the following identities:
```julia
n * invmod(n) == 1
(n * invmod(n, T)) % T == 1
(n % T) * invmod(n, T) == 1
```
Note that `*` here is modular multiplication in the integer ring, `T`.
Specifying the modulus implied by an integer type as an explicit value is often inconvenient since the modulus is by definition too big to be represented by the type.


## [Mathematical Functions](#Mathematical-Functions)
The modular inverse is computed much more efficiently than the general case using the algorithm described in https://arxiv.org/pdf/2204.04342.pdf.
The `invmod(n)` and `invmod(n, T)` methods require Julia 1.11 or later.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L260-L283)
```julia
powermod(x::Integer, p::Integer, m)
```
Compute $x^p \\pmod m$.
**Examples**
```julia-repl
julia> powermod(2, 6, 5)
4

julia> mod(2^6, 5)
4

julia> powermod(5, 2, 20)
5

julia> powermod(5, 2, 19)
6

julia> powermod(5, 3, 19)
11
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L399-L421)
```julia
ndigits(n::Integer; base::Integer=10, pad::Integer=1)
```
Compute the number of digits in integer `n` written in base `base` (`base` must not be in `[-1, 0, 1]`), optionally padded with zeros to a specified size (the result will never be less than `pad`).
See also [`digits`](../numbers/#Base.digits), [`count_ones`](../numbers/#Base.count_ones).
**Examples**
```julia-repl
julia> ndigits(0)
1

julia> ndigits(12345)
5

julia> ndigits(1022, base=16)
3

julia> string(1022, base=16)
"3fe"

julia> ndigits(123, pad=5)
5

julia> ndigits(-123)
3
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L710-L739)
```julia
Base.add_sum(x, y)
```
The reduction operator used in `sum`. The main difference from [`+`](#Base.:+) is that small integers are promoted to `Int`/`UInt`.


## [Mathematical Functions](#Mathematical-Functions)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/reduce.jl#L18-L23)
```julia
widemul(x, y)
```
Multiply `x` and `y`, giving the result as a larger type.
See also [`promote`](../base/#Base.promote), [`Base.add_sum`](#Base.add_sum).
**Examples**
```julia-repl
julia> widemul(Float32(3.0), 4.0) isa BigFloat
true

julia> typemax(Int8) * typemax(Int8)
1

julia> widemul(typemax(Int8), typemax(Int8))  # == 127^2
16129
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L258-L276)
```julia
evalpoly(x, p)
```
Evaluate the polynomial $\\sum_k x^{k-1} p\[k\]$ for the coefficients `p[1]`, `p[2]`, ...; that is, the coefficients are given in ascending order by power of `x`. Loops are unrolled at compile time if the number of coefficients is statically known, i.e. when `p` is a `Tuple`. This function generates efficient code using Horner's method if `x` is real, or using a Goertzel-like <sup>[[DK62\]](#footnote-DK62)</sup> algorithm if `x` is complex.
This function requires Julia 1.4 or later.
**Examples**
```julia-repl
julia> evalpoly(2, (1, 2, 3))
17
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/math.jl#L73-L93)
```julia
@evalpoly(z, c...)
```


## [Mathematical Functions](#Mathematical-Functions)
Evaluate the polynomial $\\sum_k z^{k-1} c\[k\]$ for the coefficients `c[1]`, `c[2]`, ...; that is, the coefficients are given in ascending order by power of `z`. This macro expands to efficient inline code that uses either Horner's method or, for complex `z`, a more efficient Goertzel-like algorithm.
See also [`evalpoly`](#Base.Math.evalpoly).
**Examples**
```julia-repl
julia> @evalpoly(3, 1, 0, 1)
10

julia> @evalpoly(2, 1, 0, 1)
5

julia> @evalpoly(2, 1, 1, 1)
7
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/math.jl#L186-L207)
```julia
@fastmath expr
```
Execute a transformed version of the expression, which calls functions that may violate strict IEEE semantics. This allows the fastest possible operation, but results are undefined – be careful when doing this, as it may change numerical results.
This sets the [LLVM Fast-Math flags](https://llvm.org/docs/LangRef.html#fast-math-flags), and corresponds to the `-ffast-math` option in clang. See [the notes on performance annotations](../../manual/performance-tips/#man-performance-annotations) for more details.
**Examples**
```julia-repl
julia> @fastmath 1+2
3

julia> @fastmath(sin(3))
0.1411200080598672
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/fastmath.jl#L131-L151)


## [Customizable binary operators](#Customizable-binary-operators)
Some unicode characters can be used to define new binary operators that support infix notation. For example `⊗(x,y) = kron(x,y)` defines the `⊗` (otimes) function to be the Kronecker product, and one can call it as binary operator using infix syntax: `C = A ⊗ B` as well as with the usual prefix syntax `C = ⊗(A,B)`.
Other characters that support such extensions include \\odot `⊙` and \\oplus `⊕`
The complete list is in the parser code: <https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm>
Those that are parsed like `*` (in terms of precedence) include `* / ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗` and those that are parsed like `+` include `+ - |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⟇ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣` There are many others that are related to arrows, comparisons, and powers.
-   [DK62](#citeref-DK62)Donald Knuth, Art of Computer Programming, Volume 2: Seminumerical Algorithms, Sec. 4.6.4.
------------------------------------------------------------------------


# Numbers · The Julia Language
Source: https://docs.julialang.org/en/v1/base/numbers/


# [Numbers](#lib-numbers)


## [Standard Numeric Types](#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.
```julia
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](#Abstract-number-types)
```julia
Number
```
Abstract supertype for all number types.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2035-L2039)
```julia
Real <: Number
```
Abstract supertype for all real numbers.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2042-L2046)
```julia
AbstractFloat <: Real
```
Abstract supertype for all floating point numbers.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2049-L2053)
```julia
Integer <: Real
```
Abstract supertype for all integers (e.g. [`Signed`](#Core.Signed), [`Unsigned`](#Core.Unsigned), and [`Bool`](#Core.Bool)).
See also [`isinteger`](#Base.isinteger), [`trunc`](../math/#Base.trunc), [`div`](../math/#Base.div).
**Examples**
```julia
julia> 42 isa Integer
true

julia> 1.0 isa Integer
false

julia> isinteger(1.0)
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2056-L2074)
```julia
Signed <: Integer
```
Abstract supertype for all signed integers.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2077-L2081)
```julia
Unsigned <: 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**


### [Abstract number types](#Abstract-number-types)
```julia
julia> typemax(UInt8)
0xff

julia> Int(0x00d)
13

julia> unsigned(true)
0x0000000000000001
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2084-L2103)
```julia
AbstractIrrational <: 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`](../base/#Base.hash) to equal that of the corresponding `Rational`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/irrationals.jl#L5-L18)


### [Concrete number types](#Concrete-number-types)
```julia
Float16 <: AbstractFloat <: Real
```
16-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 5 exponent, 10 fraction bits.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2185-L2190)
```julia
Float32 <: 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`](#Base.Inf32), [`NaN32`](#Base.NaN32), [`Float16`](#Core.Float16), [`exponent`](#Base.Math.exponent), [`frexp`](../math/#Base.Math.frexp).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2170-L2182)
```julia
Float64 <: AbstractFloat <: Real
```
64-bit floating point number type (IEEE 754 standard). Binary format is 1 sign, 11 exponent, 52 fraction bits. See [`bitstring`](#Base.bitstring), [`signbit`](../math/#Base.signbit), [`exponent`](#Base.Math.exponent), [`frexp`](../math/#Base.Math.frexp), and [`significand`](#Base.Math.significand) to access various bits.


### [Concrete number types](#Concrete-number-types)
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`](#Base.Inf), [`NaN`](#Base.NaN), [`floatmax`](../base/#Base.floatmax), [`Float32`](#Core.Float32), [`Complex`](#Base.Complex).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2150-L2167)
```julia
BigFloat <: AbstractFloat
```
Arbitrary precision floating point number type.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mpfr.jl#L122-L126)
```julia
Bool <: 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`](#Base.NaN) and [`Inf`](#Base.Inf):
```julia-repl
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`](../base/#if) and other conditionals only accept `Bool`. There are no "truthy" values in Julia.


### [Concrete number types](#Concrete-number-types)
Comparisons typically return `Bool`, and broadcasted comparisons may return [`BitArray`](../arrays/#Base.BitArray) instead of an `Array{Bool}`.
```julia-repl
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`](../arrays/#Base.trues), [`falses`](../arrays/#Base.falses), [`ifelse`](../base/#Base.ifelse).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2106-L2147)
```julia
Int8 <: 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`](#Core.Int64), [`widen`](../base/#Base.widen), [`BigInt`](#Base.GMP.BigInt).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2199-L2208)
```julia
UInt8 <: Unsigned <: Integer
```
8-bit unsigned integer type.
Printed in hexadecimal, thus 0x07 == 7.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2211-L2217)
```julia
Int16 <: 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`](#Core.Int64), [`widen`](../base/#Base.widen), [`BigInt`](#Base.GMP.BigInt).


### [Concrete number types](#Concrete-number-types)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2199-L2208)
```julia
UInt16 <: Unsigned <: Integer
```
16-bit unsigned integer type.
Printed in hexadecimal, thus 0x000f == 15.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2211-L2217)
```julia
Int32 <: Signed <: Integer
```
32-bit signed integer type.
Note that such integers overflow without warning, thus `typemax(Int32) + Int32(1) < 0`.
See also [`Int`](#Core.Int64), [`widen`](../base/#Base.widen), [`BigInt`](#Base.GMP.BigInt).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2199-L2208)
```julia
UInt32 <: Unsigned <: Integer
```
32-bit unsigned integer type.
Printed in hexadecimal, thus 0x0000001f == 31.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2211-L2217)
```julia
Int64 <: Signed <: Integer
```
64-bit signed integer type.
Note that such integers overflow without warning, thus `typemax(Int64) + Int64(1) < 0`.
See also [`Int`](#Core.Int64), [`widen`](../base/#Base.widen), [`BigInt`](#Base.GMP.BigInt).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2199-L2208)
```julia
UInt64 <: Unsigned <: Integer
```
64-bit unsigned integer type.
Printed in hexadecimal, thus 0x000000000000003f == 63.


### [Concrete number types](#Concrete-number-types)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2211-L2217)
```julia
Int128 <: Signed <: Integer
```
128-bit signed integer type.
Note that such integers overflow without warning, thus `typemax(Int128) + Int128(1) < 0`.
See also [`Int`](#Core.Int64), [`widen`](../base/#Base.widen), [`BigInt`](#Base.GMP.BigInt).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2199-L2208)
```julia
UInt128 <: Unsigned <: Integer
```
128-bit unsigned integer type.
Printed in hexadecimal, thus 0x0000000000000000000000000000007f == 127.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2211-L2217)
```julia
Int
```
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`](../collections/#Base.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`](#Base.GMP.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`](../math/#Base.div) alias `÷`, whereas [`/`](../math/#Base.:/) acting on integers returns [`Float64`](#Core.Float64).


### [Concrete number types](#Concrete-number-types)
See also [`Int64`](#Core.Int64), [`widen`](../base/#Base.widen), [`typemax`](../base/#Base.typemax), [`bitstring`](#Base.bitstring).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2222-L2239)
```julia
UInt
```
Sys.WORD_SIZE-bit unsigned integer type, `UInt <: Unsigned <: Integer`.
Like [`Int`](#Core.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`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L2242-L2251)
```julia
BigInt <: Signed
```
Arbitrary precision integer type.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/gmp.jl#L53-L57)
```julia
Complex{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`](#Core.Real), [`complex`](#Base.complex-Tuple%7BComplex%7D), [`real`](../math/#Base.real).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L3-L12)
```julia
Rational{T<:Integer} <: Real
```
Rational number type, with numerator and denominator of type `T`. Rationals are checked for overflow.


### [Concrete number types](#Concrete-number-types)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rational.jl#L3-L8)
```julia
Irrational{sym} <: AbstractIrrational
```
Number type representing an exact irrational value denoted by the symbol `sym`, such as [`π`](#Base.MathConstants.pi), [`ℯ`](#Base.MathConstants.ℯ) and [`γ`](#Base.MathConstants.eulergamma).
See also [`AbstractIrrational`](#Base.AbstractIrrational).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/irrationals.jl#L21-L28)


## [Data Formats](#Data-Formats)
```julia
digits([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 eachindex(digits))`.
See also [`ndigits`](../math/#Base.ndigits), [`digits!`](#Base.digits!), and for base 2 also [`bitstring`](#Base.bitstring), [`count_ones`](#Base.count_ones).
**Examples**
```julia-repl
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))
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L976-L1013)
```julia
digits!(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-repl
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
 0
```


## [Data Formats](#Data-Formats)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L1030-L1055)
```julia
bitstring(n)
```
A string giving the literal bit representation of a primitive type.
See also [`count_ones`](#Base.count_ones), [`count_zeros`](#Base.count_zeros), [`digits`](#Base.digits).
**Examples**
```julia-repl
julia> bitstring(Int32(4))
"00000000000000000000000000000100"

julia> bitstring(2.2)
"0100000000000001100110011001100110011001100110011001100110011010"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L942-L957)
```julia
parse(::Type{SimpleColor}, rgb::String)
```
An analogue of `tryparse(SimpleColor, rgb::String)` (which see), that raises an error instead of returning `nothing`.
```julia
parse(::Type{Platform}, triplet::AbstractString)
```
Parses a string platform triplet back into a `Platform` object.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/binaryplatforms.jl#L687-L691)
```julia
parse(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.


## [Data Formats](#Data-Formats)
`parse(Bool, str)` requires at least Julia 1.1.
**Examples**
```julia-repl
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.5im
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/parse.jl#L7-L37)
```julia
tryparse(::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-repl
julia> tryparse(SimpleColor, "blue")
SimpleColor(blue)

julia> tryparse(SimpleColor, "#9558b2")
SimpleColor(#9558b2)

julia> tryparse(SimpleColor, "#nocolor")
```
```julia
tryparse(type, str; base)
```
Like [`parse`](#Base.parse), but returns either a value of the requested type, or [`nothing`](../constants/#Core.nothing) if the string does not contain a valid number.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/parse.jl#L242-L247)
```julia
big(x)
```
Convert a number to a maximum precision representation (typically [`BigInt`](#Base.GMP.BigInt) or `BigFloat`). See [`BigFloat`](#Base.MPFR.BigFloat-Tuple%7BAny,%20RoundingMode%7D) for information about some pitfalls with floating-point numbers.


## [Data Formats](#Data-Formats)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/gmp.jl#L476-L482)
```julia
signed(T::Integer)
```
Convert an integer bitstype to the signed type of the same size.
**Examples**
```julia-repl
julia> signed(UInt16)
Int16
julia> signed(UInt64)
Int64
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L61-L72)
```julia
signed(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`](#Base.unsigned), [`sign`](../math/#Base.sign), [`signbit`](../math/#Base.signbit).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L218-L225)
```julia
unsigned(T::Integer)
```
Convert an integer bitstype to the unsigned type of the same size.
**Examples**
```julia-repl
julia> unsigned(Int16)
UInt16
julia> unsigned(UInt64)
UInt64
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L48-L59)
```julia
float(x)
```
Convert a number or array to a floating point data type.
See also: [`complex`](#Base.complex-Tuple%7BComplex%7D), [`oftype`](../base/#Base.oftype), [`convert`](../base/#Base.convert).
**Examples**
```julia-repl
julia> float(1:1000)
1.0:1.0:1000.0

julia> float(typemax(Int32))
2.147483647e9
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L358-L373)
```julia
significand(x)
```


## [Data Formats](#Data-Formats)
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`](../math/#Base.Math.frexp), [`exponent`](#Base.Math.exponent).
**Examples**
```julia-repl
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)
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/math.jl#L974-L998)
```julia
exponent(x::Real) -> Int
```
Returns the largest integer `y` such that `2^y ≤ abs(x)`.
Throws a `DomainError` when `x` is zero, infinite, or [`NaN`](#Base.NaN). For any other non-subnormal floating-point number `x`, this corresponds to the exponent bits of `x`.
See also [`signbit`](../math/#Base.signbit), [`significand`](#Base.Math.significand), [`frexp`](../math/#Base.Math.frexp), [`issubnormal`](#Base.issubnormal), [`log2`](../math/#Base.log2), [`ldexp`](../math/#Base.Math.ldexp).
**Examples**
```julia-repl
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.
[...]
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/math.jl#L913-L944)


## [Data Formats](#Data-Formats)
```julia
complex(r, [i])
```
Convert real numbers or arrays to complex. `i` defaults to zero.
**Examples**
```julia-repl
julia> complex(7)
7 + 0im

julia> complex([1, 2, 3])
3-element Vector{Complex{Int64}}:
 1 + 0im
 2 + 0im
 3 + 0im
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L156-L172)
```julia
bswap(n)
```
Reverse the byte order of `n`.
(See also [`ntoh`](../io-network/#Base.ntoh) and [`hton`](../io-network/#Base.hton) to convert between the current native byte order and big-endian order.)
**Examples**
```julia-repl
julia> a = bswap(0x10203040)
0x40302010

julia> bswap(a)
0x10203040

julia> string(1, base = 2)
"1"

julia> string(bswap(1), base = 2)
"100000000000000000000000000000000000000000000000000000000"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L375-L396)
```julia
hex2bytes(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!`](#Base.hex2bytes!) for an in-place version, and [`bytes2hex`](#Base.bytes2hex) for the inverse.


## [Data Formats](#Data-Formats)
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-repl
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
 0xef
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/util.jl#L944-L984)
```julia
hex2bytes!(dest::AbstractVector{UInt8}, itr)
```
Convert an iterable `itr` of bytes representing a hexadecimal string to its binary representation, similar to [`hex2bytes`](#Base.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.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/util.jl#L996-L1007)
```julia
bytes2hex(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.


## [Data Formats](#Data-Formats)
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-repl
julia> a = string(12345, base = 16)
"3039"

julia> b = hex2bytes(a)
2-element Vector{UInt8}:
 0x30
 0x39

julia> bytes2hex(b)
"3039"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/util.jl#L1033-L1059)


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
```julia
one(x)
one(T::type)
```
Return a multiplicative identity for `x`: a value such that `one(x)*x == x*one(x) == x`. Alternatively `one(T)` can take a type `T`, in which case `one` returns a multiplicative identity for any `x` of type `T`.
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`](#Base.oneunit) instead.
See also the [`identity`](../base/#Base.identity) function, and `I` in [`LinearAlgebra`](../../stdlib/LinearAlgebra/#man-linalg) for the identity matrix.
**Examples**
```julia-repl
julia> one(3.7)
1.0

julia> one(Int)
1

julia> import Dates; one(Dates.Day(1))
1
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L312-L346)
```julia
oneunit(x::T)
oneunit(T::Type)
```
Return `T(one(x))`, where `T` is either the type of the argument or (if a type is passed) the argument. This differs from [`one`](#Base.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**


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
```julia-repl
julia> oneunit(3.7)
1.0

julia> import Dates; oneunit(Dates.Day)
1 day
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L353-L370)
```julia
zero(x)
zero(::Type)
```
Get the additive identity element for the type of `x` (`x` can also specify the type itself).
See also [`iszero`](#Base.iszero), [`one`](#Base.one), [`oneunit`](#Base.oneunit), [`oftype`](../base/#Base.oftype).
**Examples**
```julia-repl
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.0
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L286-L307)
```julia
im
```
The imaginary unit.
See also: [`imag`](../math/#Base.imag), [`angle`](../math/#Base.angle), [`complex`](#Base.complex-Tuple%7BComplex%7D).
**Examples**
```julia-repl
julia> im * im
-1 + 0im

julia> (2.0 + 3im)^2
-5.0 + 12.0im
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L20-L35)
```julia
π
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`](../math/#Base.Math.sinpi), [`sincospi`](../math/#Base.Math.sincospi), [`deg2rad`](../math/#Base.Math.deg2rad).
**Examples**
```julia-repl
julia> pi
π = 3.1415926535897...

julia> 1/2pi
0.15915494309189535
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mathconstants.jl#L40-L58)
```julia
ℯ
e
```
The constant ℯ.
Unicode `ℯ` can be typed by writing `\euler` and pressing tab in the Julia REPL, and in many editors.
See also: [`exp`](../math/#Base.exp-Tuple%7BFloat64%7D), [`cis`](../math/#Base.cis), [`cispi`](../math/#Base.cispi).
**Examples**
```julia-repl
julia> ℯ
ℯ = 2.7182818284590...

julia> log(ℯ)
1

julia> ℯ^(im)π ≈ -1
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mathconstants.jl#L61-L82)
```julia
catalan
```
Catalan's constant.
**Examples**
```julia-repl
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.9159466120554123
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mathconstants.jl#L121-L134)
```julia
γ
eulergamma
```
Euler's constant.
**Examples**
```julia-repl
julia> Base.MathConstants.eulergamma
γ = 0.5772156649015...

julia> dx = 10^-6;

julia> sum(-exp(-x) * log(x) for x in dx:dx:100) * dx
0.5772078382499133
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mathconstants.jl#L85-L101)
```julia
φ
golden
```
The golden ratio.
**Examples**
```julia-repl
julia> Base.MathConstants.golden
φ = 1.6180339887498...

julia> (2ans - 1)^2 ≈ 5
true
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mathconstants.jl#L104-L118)
```julia
Inf, Inf64
```
Positive infinity of type [`Float64`](#Core.Float64).
See also: [`isfinite`](#Base.isfinite), [`typemax`](../base/#Base.typemax), [`NaN`](#Base.NaN), [`Inf32`](#Base.Inf32).
**Examples**
```julia-repl
julia> π/0
Inf

julia> +1.0 / -0.0
-Inf

julia> ℯ^-Inf
0.0
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L39-L57)
```julia
Inf, Inf64
```
Positive infinity of type [`Float64`](#Core.Float64).
See also: [`isfinite`](#Base.isfinite), [`typemax`](../base/#Base.typemax), [`NaN`](#Base.NaN), [`Inf32`](#Base.Inf32).
**Examples**
```julia-repl
julia> π/0
Inf

julia> +1.0 / -0.0
-Inf

julia> ℯ^-Inf
0.0
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L39-L57)
```julia
Inf32
```
Positive infinity of type [`Float32`](#Core.Float32).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L21-L25)
```julia
Inf16
```
Positive infinity of type [`Float16`](#Core.Float16).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L7-L11)
```julia
NaN, NaN64
```
A not-a-number value of type [`Float64`](#Core.Float64).
See also: [`isnan`](#Base.isnan), [`missing`](../../manual/missing/#missing), [`NaN32`](#Base.NaN32), [`Inf`](#Base.Inf).
**Examples**


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
```julia-repl
julia> 0/0
NaN

julia> Inf - Inf
NaN

julia> NaN == NaN, isequal(NaN, NaN), isnan(NaN)
(false, true, true)
```
Always use [`isnan`](#Base.isnan) or [`isequal`](../base/#Base.isequal) for checking for `NaN`. Using `x === NaN` may give unexpected results:
```julia-repl
julia> reinterpret(UInt32, NaN32)
0x7fc00000

julia> NaN32p1 = reinterpret(Float32, 0x7fc00001)
NaN32

julia> NaN32p1 === NaN32, isequal(NaN32p1, NaN32), isnan(NaN32p1)
(false, true, true)
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L61-L93)
```julia
NaN, NaN64
```
A not-a-number value of type [`Float64`](#Core.Float64).
See also: [`isnan`](#Base.isnan), [`missing`](../../manual/missing/#missing), [`NaN32`](#Base.NaN32), [`Inf`](#Base.Inf).
**Examples**
```julia-repl
julia> 0/0
NaN

julia> Inf - Inf
NaN

julia> NaN == NaN, isequal(NaN, NaN), isnan(NaN)
(false, true, true)
```
Always use [`isnan`](#Base.isnan) or [`isequal`](../base/#Base.isequal) for checking for `NaN`. Using `x === NaN` may give unexpected results:
```julia-repl
julia> reinterpret(UInt32, NaN32)
0x7fc00000

julia> NaN32p1 = reinterpret(Float32, 0x7fc00001)
NaN32

julia> NaN32p1 === NaN32, isequal(NaN32p1, NaN32), isnan(NaN32p1)
(false, true, true)
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L61-L93)
```julia
NaN32
```
A not-a-number value of type [`Float32`](#Core.Float32).
See also: [`NaN`](#Base.NaN).


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L27-L33)
```julia
NaN16
```
A not-a-number value of type [`Float16`](#Core.Float16).
See also: [`NaN`](#Base.NaN).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L13-L19)
```julia
issubnormal(f) -> Bool
```
Test whether a floating point number is subnormal.
An IEEE floating point number is [subnormal](https://en.wikipedia.org/wiki/Subnormal_number) when its exponent bits are zero and its significand is not zero.
**Examples**
```julia-repl
julia> floatmin(Float32)
1.1754944f-38

julia> issubnormal(1.0f-37)
false

julia> issubnormal(1.0f-38)
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L1002-L1021)
```julia
isfinite(f) -> Bool
```
Test whether a number is finite.
**Examples**
```julia-repl
julia> isfinite(5)
true

julia> isfinite(NaN32)
false
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L64-L77)
```julia
isinf(f) -> Bool
```
Test whether a number is infinite.
See also: [`Inf`](#Base.Inf), [`iszero`](#Base.iszero), [`isfinite`](#Base.isfinite), [`isnan`](#Base.isnan).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L709-L715)
```julia
isnan(f) -> Bool
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
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`](#Base.iszero), [`isone`](#Base.isone), [`isinf`](#Base.isinf), [`ismissing`](../base/#Base.ismissing).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L694-L701)
```julia
iszero(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`](#Base.isone), [`isinteger`](#Base.isinteger), [`isfinite`](#Base.isfinite), [`isnan`](#Base.isnan).
**Examples**
```julia-repl
julia> iszero(0.0)
true

julia> iszero([1, 9, 0])
false

julia> iszero([false, 0, 0])
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L22-L41)
```julia
isone(x)
```
Return `true` if `x == one(x)`; if `x` is an array, this checks whether `x` is an identity matrix.
**Examples**
```julia-repl
julia> isone(1.0)
true

julia> isone([1 0; 0 2])
false

julia> isone([1 0; 0 true])
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L44-L61)
```julia
nextfloat(x::AbstractFloat, n::Integer)
```
The result of `n` iterative applications of `nextfloat` to `x` if `n >= 0`, or `-n` applications of [`prevfloat`](#Base.prevfloat) if `n < 0`.


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L882-L887)
```julia
nextfloat(x::AbstractFloat)
```
Return the smallest floating point number `y` of the same type as `x` such `x < y`. If no such `y` exists (e.g. if `x` is `Inf` or `NaN`), then return `x`.
See also: [`prevfloat`](#Base.prevfloat), [`eps`](../base/#Base.eps-Tuple%7BType%7B%3C:AbstractFloat%7D%7D), [`issubnormal`](#Base.issubnormal).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L926-L933)
```julia
prevfloat(x::AbstractFloat, n::Integer)
```
The result of `n` iterative applications of `prevfloat` to `x` if `n >= 0`, or `-n` applications of [`nextfloat`](#Base.nextfloat) if `n < 0`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L936-L941)
```julia
prevfloat(x::AbstractFloat)
```
Return the largest floating point number `y` of the same type as `x` such `y < x`. If no such `y` exists (e.g. if `x` is `-Inf` or `NaN`), then return `x`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L944-L949)
```julia
isinteger(x) -> Bool
```
Test whether `x` is numerically equal to some integer.
**Examples**
```julia-repl
julia> isinteger(4.0)
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/number.jl#L9-L19)
```julia
isreal(x) -> Bool
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
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-repl
julia> isreal(5.)
true

julia> isreal(1 - 3im)
false

julia> isreal(Inf + 0im)
true

julia> isreal([4.; complex(0,1)])
false
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/complex.jl#L125-L146)
```julia
Float32(x [, mode::RoundingMode])
```
Create a `Float32` from `x`. If `x` is not exactly representable then `mode` determines how `x` is rounded.
**Examples**
```julia-repl
julia> Float32(1/3, RoundDown)
0.3333333f0

julia> Float32(1/3, RoundUp)
0.33333334f0
```
See [`RoundingMode`](../math/#Base.Rounding.RoundingMode) for available rounding modes.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L1682-L1698)
```julia
Float64(x [, mode::RoundingMode])
```
Create a `Float64` from `x`. If `x` is not exactly representable then `mode` determines how `x` is rounded.
**Examples**
```julia-repl
julia> Float64(pi, RoundDown)
3.141592653589793

julia> Float64(pi, RoundUp)
3.1415926535897936
```
See [`RoundingMode`](../math/#Base.Rounding.RoundingMode) for available rounding modes.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/basedocs.jl#L1701-L1717)
```julia
rounding(T)
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
Get the current floating point rounding mode for type `T`, controlling the rounding of basic arithmetic functions ([`+`](../math/#Base.:+), [`-`](../math/#Base.:--Tuple%7BAny%7D), [`*`](../math/#Base.:*-Tuple%7BAny,%20Vararg%7BAny%7D%7D), [`/`](../math/#Base.:/) and [`sqrt`](../math/#Base.sqrt-Tuple%7BNumber%7D)) and type conversion.
See [`RoundingMode`](../math/#Base.Rounding.RoundingMode) for available modes.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rounding.jl#L208-L216)
```julia
setrounding(T, mode)
```
Set the rounding mode of floating point type `T`, controlling the rounding of basic arithmetic functions ([`+`](../math/#Base.:+), [`-`](../math/#Base.:--Tuple%7BAny%7D), [`*`](../math/#Base.:*-Tuple%7BAny,%20Vararg%7BAny%7D%7D), [`/`](../math/#Base.:/) and [`sqrt`](../math/#Base.sqrt-Tuple%7BNumber%7D)) and type conversion. Other numerical functions may give incorrect or invalid values when using rounding modes other than the default [`RoundNearest`](../math/#Base.Rounding.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.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rounding.jl#L189-L205)
```julia
setrounding(f::Function, T, mode)
```


## [General Number Functions and Constants](#General-Number-Functions-and-Constants)
Change the rounding mode of floating point type `T` for the duration of `f`. It is logically equivalent to:
```julia
old = rounding(T)
setrounding(T, mode)
f()
setrounding(T, old)
```
See [`RoundingMode`](../math/#Base.Rounding.RoundingMode) for available rounding modes.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rounding.jl#L224-L236)
```julia
get_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.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rounding.jl#L304-L313)
```julia
set_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](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/rounding.jl#L287-L301)


### [Integers](#Integers)
```julia
count_ones(x::Integer) -> Integer
```
Number of ones in the binary representation of `x`.
**Examples**
```julia-repl
julia> count_ones(7)
3

julia> count_ones(Int32(-1))
32
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L401-L414)
```julia
count_zeros(x::Integer) -> Integer
```
Number of zeros in the binary representation of `x`.
**Examples**
```julia-repl
julia> count_zeros(Int32(2 ^ 16 - 1))
16

julia> count_zeros(-1)
0
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L443-L456)
```julia
leading_zeros(x::Integer) -> Integer
```
Number of zeros leading the binary representation of `x`.
**Examples**
```julia-repl
julia> leading_zeros(Int32(1))
31
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L417-L427)
```julia
leading_ones(x::Integer) -> Integer
```
Number of ones leading the binary representation of `x`.
**Examples**
```julia-repl
julia> leading_ones(UInt32(2 ^ 32 - 2))
31
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L459-L469)
```julia
trailing_zeros(x::Integer) -> Integer
```
Number of zeros trailing the binary representation of `x`.
**Examples**
```julia-repl
julia> trailing_zeros(2)
1
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L430-L440)
```julia
trailing_ones(x::Integer) -> Integer
```


### [Integers](#Integers)
Number of ones trailing the binary representation of `x`.
**Examples**
```julia-repl
julia> trailing_ones(3)
2
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L472-L482)
```julia
isodd(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-repl
julia> isodd(9)
true

julia> isodd(10)
false
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L99-L115)
```julia
iseven(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-repl
julia> iseven(9)
false

julia> iseven(10)
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L119-L135)
```julia
@int128_str str
```
Parse `str` as an [`Int128`](#Core.Int128). Throw an `ArgumentError` if the string is not a valid integer.
**Examples**
```julia-repl
julia> int128"123456789123"
123456789123

julia> int128"123456789123.4"
ERROR: LoadError: ArgumentError: invalid base 10 digit '.' in "123456789123.4"
[...]
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L634-L649)
```julia
@uint128_str str
```
Parse `str` as an [`UInt128`](#Core.UInt128). Throw an `ArgumentError` if the string is not a valid integer.


### [Integers](#Integers)
**Examples**
```julia
julia> uint128"123456789123"
0x00000000000000000000001cbe991a83

julia> uint128"-123456789123"
ERROR: LoadError: ArgumentError: invalid base 10 digit '-' in "-123456789123"
[...]
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L654-L669)


## [BigFloats and BigInts](#BigFloats-and-BigInts)
The [`BigFloat`](#Base.MPFR.BigFloat) and [`BigInt`](#Base.GMP.BigInt) types implements arbitrary-precision floating point and integer arithmetic, respectively. For [`BigFloat`](#Base.MPFR.BigFloat) the [GNU MPFR library](https://www.mpfr.org/) is used, and for [`BigInt`](#Base.GMP.BigInt) the [GNU Multiple Precision Arithmetic Library (GMP)](https://gmplib.org) is used.
```julia
BigFloat(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`](#Base.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`](#Core.@big_str)
-   [`rounding`](#Base.Rounding.rounding) and [`setrounding`](#Base.Rounding.setrounding-Tuple%7BType,%20Any%7D)
-   [`precision`](#Base.precision) and [`setprecision`](#Base.MPFR.setprecision)


## [BigFloats and BigInts](#BigFloats-and-BigInts)
`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-repl
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.100000000000000000000000000000000000007
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mpfr.jl#L179-L217)
```julia
precision(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`](#Base.MPFR.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.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/float.jl#L854-L867)
```julia
setprecision([T=BigFloat,] precision::Int; base=2)
```


## [BigFloats and BigInts](#BigFloats-and-BigInts)
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.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mpfr.jl#L964-L979)
```julia
setprecision(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:
```julia
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`.
The `base` keyword requires at least Julia 1.8.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/mpfr.jl#L1080-L1098)
```julia
BigInt(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`](#Base.GMP.BigInt).
Instances can be constructed from strings via [`parse`](#Base.parse), or using the `big` string literal.
**Examples**


## [BigFloats and BigInts](#BigFloats-and-BigInts)
```julia-repl
julia> parse(BigInt, "42")
42

julia> big"313"
313

julia> BigInt(10)^19
10000000000000000000
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/gmp.jl#L70-L91)
```julia
@big_str str
```
Parse a string into a [`BigInt`](#Base.GMP.BigInt) or [`BigFloat`](#Base.MPFR.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-repl
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`](#Base.MPFR.BigFloat) values may not result in the behavior that might be naively expected: as a macro, `@big_str` obeys the global precision ([`setprecision`](#Base.MPFR.setprecision)) and rounding mode ([`setrounding`](#Base.Rounding.setrounding-Tuple%7BType,%20Any%7D)) 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](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/int.jl#L674-L702)
------------------------------------------------------------------------


# Strings · The Julia Language
Source: https://docs.julialang.org/en/v1/base/strings/


# [Strings](#lib-strings)
The `AbstractString` type is the supertype of all string implementations in Julia. Strings are encodings of sequences of [Unicode](https://unicode.org/) code points as represented by the `AbstractChar` type. Julia makes a few assumptions about strings:
-   Strings are encoded in terms of fixed-size "code units"
    -   Code units can be extracted with `codeunit(s, i)`
    -   The first code unit has index `1`
    -   The last code unit has index `ncodeunits(s)`
    -   Any index `i` such that `1 ≤ i ≤ ncodeunits(s)` is in bounds
-   String indexing is done in terms of these code units:
    -   Characters are extracted by `s[i]` with a valid string index `i`
    -   Each `AbstractChar` in a string is encoded by one or more code units
    -   Only the index of the first code unit of an `AbstractChar` is a valid index
    -   The encoding of an `AbstractChar` is independent of what precedes or follows it
    -   String encodings are [self-synchronizing](https://en.wikipedia.org/wiki/Self-synchronizing_code) – i.e. `isvalid(s, i)` is O(1)


# [Strings](#lib-strings)
Some string functions that extract code units, characters or substrings from strings error if you pass them out-of-bounds or invalid string indices. This includes `codeunit(s, i)` and `s[i]`. Functions that do string index arithmetic take a more relaxed approach to indexing and give you the closest valid string index when in-bounds, or when out-of-bounds, behave as if there were an infinite number of characters padding each side of the string. Usually these imaginary padding characters have code unit length `1` but string types may choose different "imaginary" character sizes as makes sense for their implementations (e.g. substrings may pass index arithmetic through to the underlying string they provide a view into). Relaxed indexing functions include those intended for index arithmetic: `thisind`, `nextind` and `prevind`. This model allows index arithmetic to work with out-of-bounds indices as intermediate values so long as one never uses them to retrieve a character, which often helps avoid needing to code around edge cases.
See also [`codeunit`](#Base.codeunit), [`ncodeunits`](#Base.ncodeunits-Tuple%7BAbstractString%7D), [`thisind`](#Base.thisind), [`nextind`](../arrays/#Base.nextind), [`prevind`](../arrays/#Base.prevind).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L3-L38)


# [Strings](#lib-strings)
The `AbstractChar` type is the supertype of all character implementations in Julia. A character represents a Unicode code point, and can be converted to an integer via the [`codepoint`](#Base.codepoint) function in order to obtain the numerical value of the code point, or constructed from the same integer. These numerical values determine how characters are compared with `<` and `==`, for example. New `T <: AbstractChar` types should define a `codepoint(::T)` method and a `T(::UInt32)` constructor, at minimum.
A given `AbstractChar` subtype may be capable of representing only a subset of Unicode, in which case conversion from an unsupported `UInt32` value may throw an error. Conversely, the built-in [`Char`](#Core.Char) type represents a *superset* of Unicode (in order to losslessly encode invalid byte streams), in which case conversion of a non-Unicode value *to* `UInt32` throws an error. The [`isvalid`](#Base.isvalid-Tuple%7BAny%7D) function can be used to check which codepoints are representable in a given `AbstractChar` type.
Internally, an `AbstractChar` type may use a variety of encodings. Conversion via `codepoint(char)` will not reveal this encoding because it always returns the Unicode value of the character. `print(io, c)` of any `c::AbstractChar` produces an encoding determined by `io` (UTF-8 for all built-in `IO` types), via conversion to `Char` if necessary.


# [Strings](#lib-strings)
`write(io, c)`, in contrast, may emit an encoding depending on `typeof(c)`, and `read(io, typeof(c))` should read the same encoding as `write`. New `AbstractChar` types must provide their own implementations of `write` and `read`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/char.jl#L3-L30)
```julia
Char(c::Union{Number,AbstractChar})
```
`Char` is a 32-bit [`AbstractChar`](#Core.AbstractChar) type that is the default representation of characters in Julia. `Char` is the type used for character literals like `'x'` and it is also the element type of [`String`](#Core.String-Tuple%7BAbstractString%7D).
In order to losslessly represent arbitrary byte streams stored in a `String`, a `Char` value may store information that cannot be converted to a Unicode codepoint — converting such a `Char` to `UInt32` will throw an error. The [`isvalid(c::Char)`](#Base.isvalid-Tuple%7BAny%7D) function can be used to query whether `c` represents a valid Unicode character.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/char.jl#L33-L45)
```julia
codepoint(c::AbstractChar) -> Integer
```
Return the Unicode codepoint (an unsigned integer) corresponding to the character `c` (or throw an exception if `c` does not represent a valid character). For `Char`, this is a `UInt32` value, but `AbstractChar` types that represent only a subset of Unicode may return a different-sized integer (e.g. `UInt8`).


# [Strings](#lib-strings)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/char.jl#L67-L75)
```julia
length(s::AbstractString) -> Int
length(s::AbstractString, i::Integer, j::Integer) -> Int
```
Return the number of characters in string `s` from indices `i` through `j`.
This is computed as the number of code unit indices from `i` to `j` which are valid character indices. With only a single string argument, this computes the number of characters in the entire string. With `i` and `j` arguments it computes the number of indices between `i` and `j` inclusive that are valid indices in the string `s`. In addition to in-bounds values, `i` may take the out-of-bounds value `ncodeunits(s) + 1` and `j` may take the out-of-bounds value `0`.
The time complexity of this operation is linear in general. That is, it will take the time proportional to the number of bytes or characters in the string because it counts the value on the fly. This is in contrast to the method for arrays, which is a constant-time operation.
See also [`isvalid`](#Base.isvalid-Tuple%7BAny%7D), [`ncodeunits`](#Base.ncodeunits-Tuple%7BAbstractString%7D), [`lastindex`](../collections/#Base.lastindex), [`thisind`](#Base.thisind), [`nextind`](../arrays/#Base.nextind), [`prevind`](../arrays/#Base.prevind).
**Examples**
```julia-repl
julia> length("jμΛIα")
5
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L375-L403)
```julia
sizeof(str::AbstractString)
```


# [Strings](#lib-strings)
Size, in bytes, of the string `str`. Equal to the number of code units in `str` multiplied by the size, in bytes, of one code unit in `str`.
**Examples**
```julia-repl
julia> sizeof("")
0

julia> sizeof("∀")
3
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L162-L176)
```julia
*(s::Union{AbstractString, AbstractChar}, t::Union{AbstractString, AbstractChar}...) -> AbstractString
```
Concatenate strings and/or characters, producing a [`String`](#Core.String-Tuple%7BAbstractString%7D) or [`AnnotatedString`](#Base.AnnotatedString) (as appropriate). This is equivalent to calling the [`string`](#Base.string) or [`annotatedstring`](#Base.annotatedstring) function on the arguments. Concatenation of built-in string types always produces a value of type `String` but other string types may choose to return a string of a different type as appropriate.
**Examples**
```julia-repl
julia> "Hello " * "world"
"Hello world"

julia> 'j' * "ulia"
"julia"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L243-L260)
```julia
^(s::Union{AbstractString,AbstractChar}, n::Integer) -> AbstractString
```
Repeat a string or character `n` times. This can also be written as `repeat(s, n)`.
See also [`repeat`](../arrays/#Base.repeat).
**Examples**
```julia-repl
julia> "Test "^3
"Test Test Test "
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L766-L778)


# [Strings](#lib-strings)
```julia
string(n::Integer; base::Integer = 10, pad::Integer = 1)
```
Convert an integer `n` to a string in the given `base`, optionally specifying a number of digits to pad to.
See also [`digits`](../numbers/#Base.digits), [`bitstring`](../numbers/#Base.bitstring), [`count_zeros`](../numbers/#Base.count_zeros).
**Examples**
```julia-repl
julia> string(5, base = 13, pad = 4)
"0005"

julia> string(-13, base = 5, pad = 4)
"-0023"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/intfuncs.jl#L904-L920)
```julia
string(xs...)
```
Create a string from any values using the [`print`](../io-network/#Base.print) function.
`string` should usually not be defined directly. Instead, define a method `print(io::IO, x::MyType)`. If `string(x)` for a certain type needs to be highly efficient, then it may make sense to add a method to `string` and define `print(io::IO, x::MyType) = print(io, string(x))` to ensure the functions are consistent.
See also: [`String`](#Core.String-Tuple%7BAbstractString%7D), [`repr`](../io-network/#Base.repr-Tuple%7BMIME,%20Any%7D), [`sprint`](../io-network/#Base.sprint), [`show`](../base/#Base.@show).
**Examples**
```julia-repl
julia> string("a", 1, true)
"a1true"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/io.jl#L170-L188)
```julia
repeat(s::AbstractString, r::Integer)
```
Repeat a string `r` times. This can be written as `s^r`.
See also [`^`](#Base.:%5E-Tuple%7BUnion%7BAbstractChar,%20AbstractString%7D,%20Integer%7D).


# [Strings](#lib-strings)
**Examples**
```julia-repl
julia> repeat("ha", 3)
"hahaha"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L751-L763)
```julia
repeat(c::AbstractChar, r::Integer) -> String
```
Repeat a character `r` times. This can equivalently be accomplished by calling [`c^r`](#Base.:%5E-Tuple%7BUnion%7BAbstractChar,%20AbstractString%7D,%20Integer%7D).
**Examples**
```julia-repl
julia> repeat('A', 3)
"AAA"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/string.jl#L560-L571)
```julia
repr(x; context=nothing)
```
Create a string from any value using the [`show`](../io-network/#Base.show-Tuple%7BIO,%20Any%7D) function. You should not add methods to `repr`; define a `show` method instead.
The optional keyword argument `context` can be set to a `:key=>value` pair, a tuple of `:key=>value` pairs, or an `IO` or [`IOContext`](../io-network/#Base.IOContext) object whose attributes are used for the I/O stream passed to `show`.
Note that `repr(x)` is usually similar to how the value of `x` would be entered in Julia. See also [`repr(MIME("text/plain"), x)`](../io-network/#Base.repr-Tuple%7BMIME,%20Any%7D) to instead return a "pretty-printed" version of `x` designed more for human consumption, equivalent to the REPL display of `x`.
Passing a tuple to keyword `context` requires Julia 1.7 or later.
**Examples**


# [Strings](#lib-strings)
```julia-repl
julia> repr(1)
"1"

julia> repr(zeros(3))
"[0.0, 0.0, 0.0]"

julia> repr(big(1/3))
"0.333333333333333314829616256247390992939472198486328125"

julia> repr(big(1/3), context=:compact => true)
"0.333333"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/io.jl#L252-L285)
```julia
String(s::AbstractString)
```
Create a new `String` from an existing `AbstractString`.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/string.jl#L111-L115)
```julia
SubString(s::AbstractString, i::Integer, j::Integer=lastindex(s))
SubString(s::AbstractString, r::UnitRange{<:Integer})
```
Like [`getindex`](../collections/#Base.getindex), but returns a view into the parent string `s` within range `i:j` or `r` respectively instead of making a copy.
The [`@views`](../arrays/#Base.@views) macro converts any string slices `s[i:j]` into substrings `SubString(s, i, j)` in a block of code.
**Examples**
```julia-repl
julia> SubString("abc", 1, 2)
"ab"

julia> SubString("abc", 1:2)
"ab"

julia> SubString("abc", 2)
"bc"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/substring.jl#L3-L24)
```julia
LazyString <: AbstractString
```
A lazy representation of string interpolation. This is useful when a string needs to be constructed in a context where performing the actual interpolation and string construction is unnecessary or undesirable (e.g. in error paths of functions).


# [Strings](#lib-strings)
This type is designed to be cheap to construct at runtime, trying to offload as much work as possible to either the macro or later printing operations.
**Examples**
```julia-repl
julia> n = 5; str = LazyString("n is ", n)
"n is 5"
```
See also [`@lazy_str`](#Base.@lazy_str).
`LazyString` requires Julia 1.8 or later.
**Extended help**
**Safety properties for concurrent programs**
A lazy string itself does not introduce any concurrency problems even if it is printed in multiple Julia tasks. However, if `print` methods on a captured value can have a concurrency issue when invoked without synchronizations, printing the lazy string may cause an issue. Furthermore, the `print` methods on the captured values may be invoked multiple times, though only exactly one result will be returned.
`LazyString` is safe in the above sense in Julia 1.9 and later.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/lazy.jl#L1-L35)
```julia
lazy"str"
```
Create a [`LazyString`](#Base.LazyString) using regular string interpolation syntax. Note that interpolations are *evaluated* at LazyString construction time, but *printing* is delayed until the first access to the string.
See [`LazyString`](#Base.LazyString) documentation for the safety properties for concurrent programs.
**Examples**
```julia
julia> n = 5; str = lazy"n is $n"
"n is 5"

julia> typeof(str)
LazyString
```
`lazy"str"` requires Julia 1.8 or later.


# [Strings](#lib-strings)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/lazy.jl#L44-L65)
```julia
transcode(T, src)
```
Convert string data between Unicode encodings. `src` is either a `String` or a `Vector{UIntXX}` of UTF-XX code units, where `XX` is 8, 16, or 32. `T` indicates the encoding of the return value: `String` to return a (UTF-8 encoded) `String` or `UIntXX` to return a `Vector{UIntXX}` of UTF-`XX` data. (The alias [`Cwchar_t`](../c/#Base.Cwchar_t) can also be used as the integer type, for converting `wchar_t*` strings used by external C libraries.)
The `transcode` function succeeds as long as the input data can be reasonably represented in the target encoding; it always succeeds for conversions between UTF-XX encodings, even for invalid Unicode data.
Only conversion to/from UTF-8 is currently supported.
**Examples**
```julia-repl
julia> str = "αβγ"
"αβγ"

julia> transcode(UInt16, str)
3-element Vector{UInt16}:
 0x03b1
 0x03b2
 0x03b3

julia> transcode(String, transcode(UInt16, str))
"αβγ"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/cstring.jl#L129-L160)
```julia
unsafe_string(p::Ptr{UInt8}, [length::Integer])
```
Copy a string from the address of a C-style (NUL-terminated) string encoded as UTF-8. (The pointer can be safely freed afterwards.) If `length` is specified (the length of the data in bytes), the string does not have to be NUL-terminated.


# [Strings](#lib-strings)
This function is labeled "unsafe" because it will crash if `p` is not a valid memory address to data of the requested length.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/string.jl#L88-L97)
```julia
ncodeunits(s::AbstractString) -> Int
```
Return the number of code units in a string. Indices that are in bounds to access this string must satisfy `1 ≤ i ≤ ncodeunits(s)`. Not all such indices are valid – they may not be the start of a character, but they will return a code unit value when calling `codeunit(s,i)`.
**Examples**
```julia-repl
julia> ncodeunits("The Julia Language")
18

julia> ncodeunits("∫eˣ")
6

julia> ncodeunits('∫'), ncodeunits('e'), ncodeunits('ˣ')
(3, 1, 2)
```
See also [`codeunit`](#Base.codeunit), [`checkbounds`](../arrays/#Base.checkbounds), [`sizeof`](../base/#Base.sizeof-Tuple%7BType%7D), [`length`](../collections/#Base.length), [`lastindex`](../collections/#Base.lastindex).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L43-L65)
```julia
codeunit(s::AbstractString) -> Type{<:Union{UInt8, UInt16, UInt32}}
```


# [Strings](#lib-strings)
Return the code unit type of the given string object. For ASCII, Latin-1, or UTF-8 encoded strings, this would be `UInt8`; for UCS-2 and UTF-16 it would be `UInt16`; for UTF-32 it would be `UInt32`. The code unit type need not be limited to these three types, but it's hard to think of widely used string encodings that don't use one of these units. `codeunit(s)` is the same as `typeof(codeunit(s,1))` when `s` is a non-empty string.
See also [`ncodeunits`](#Base.ncodeunits-Tuple%7BAbstractString%7D).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L68-L79)
```julia
codeunit(s::AbstractString, i::Integer) -> Union{UInt8, UInt16, UInt32}
```
Return the code unit value in the string `s` at index `i`. Note that
```julia
codeunit(s, i) :: codeunit(s)
```
I.e. the value returned by `codeunit(s, i)` is of the type returned by `codeunit(s)`.
**Examples**
```julia-repl
julia> a = codeunit("Hello", 2)
0x65

julia> typeof(a)
UInt8
```
See also [`ncodeunits`](#Base.ncodeunits-Tuple%7BAbstractString%7D), [`checkbounds`](../arrays/#Base.checkbounds).
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L84-L104)
```julia
codeunits(s::AbstractString)
```
Obtain a vector-like object containing the code units of a string. Returns a `CodeUnits` wrapper by default, but `codeunits` may optionally be defined for new string types if necessary.
**Examples**


# [Strings](#lib-strings)
```julia-repl
julia> codeunits("Juλia")
6-element Base.CodeUnits{UInt8, String}:
 0x4a
 0x75
 0xce
 0xbb
 0x69
 0x61
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L812-L830)
```julia
ascii(s::AbstractString)
```
Convert a string to `String` type and check that it contains only ASCII data, otherwise throwing an `ArgumentError` indicating the position of the first non-ASCII byte.
See also the [`isascii`](#Base.isascii) predicate to filter or replace non-ASCII characters.
**Examples**
```julia-repl
julia> ascii("abcdeγfgh")
ERROR: ArgumentError: invalid ASCII at index 6 in "abcdeγfgh"
Stacktrace:
[...]

julia> ascii("abcdefgh")
"abcdefgh"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/util.jl#L1088-L1106)
```julia
Regex(pattern[, flags]) <: AbstractPattern
```
A type representing a regular expression. `Regex` objects can be used to match strings with [`match`](#Base.match).
`Regex` objects can be created using the [`@r_str`](#Base.@r_str) string macro. The `Regex(pattern[, flags])` constructor is usually used if the `pattern` string needs to be interpolated. See the documentation of the string macro for details on flags.
To escape interpolated variables use `\Q` and `\E` (e.g. `Regex("\\Q$x\\E")`)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L10-L22)
```julia
@r_str -> Regex
```


# [Strings](#lib-strings)
Construct a regex, such as `r"^[a-z]*$"`, without interpolation and unescaping (except for quotation mark `"` which still has to be escaped). The regex also accepts one or more flags, listed after the ending quote, to change its behaviour:
-   `i` enables case-insensitive matching
-   `m` treats the `^` and `$` tokens as matching the start and end of individual lines, as opposed to the whole string.
-   `s` allows the `.` modifier to match newlines.
-   `x` enables "free-spacing mode": whitespace between regex tokens is ignored except when escaped with `\`, and `#` in the regex is treated as starting a comment (which is ignored to the line ending).
-   `a` enables ASCII mode (disables `UTF` and `UCP` modes). By default `\B`, `\b`, `\D`, `\d`, `\S`, `\s`, `\W`, `\w`, etc. match based on Unicode character properties. With this option, these sequences only match ASCII characters. This includes `\u` also, which will emit the specified character value directly as a single byte, and not attempt to encode it into UTF-8. Importantly, this option allows matching against invalid UTF-8 strings, by treating both matcher and target as simple bytes (as if they were ISO/IEC 8859-1 / Latin-1 bytes) instead of as character encodings. In this case, this option is often combined with `s`. This option can be further refined by starting the pattern with (*UCP) or (*UTF).
See [`Regex`](#Base.Regex) if interpolation is needed.
**Examples**
```julia-repl
julia> match(r"a+.*b+.*?d$"ism, "Goodbye,\nOh, angry,\nBad world\n")
RegexMatch("angry,\nBad world")
```


# [Strings](#lib-strings)
This regex has the first three flags enabled.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L97-L128)
```julia
SubstitutionString(substr) <: AbstractString
```
Stores the given string `substr` as a `SubstitutionString`, for use in regular expression substitutions. Most commonly constructed using the [`@s_str`](#Base.@s_str) macro.
**Examples**
```julia-repl
julia> SubstitutionString("Hello \\g<name>, it's \\1")
s"Hello \g<name>, it's \1"

julia> subst = s"Hello \g<name>, it's \1"
s"Hello \g<name>, it's \1"

julia> typeof(subst)
SubstitutionString{String}
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L564-L581)
```julia
@s_str -> SubstitutionString
```
Construct a substitution string, used for regular expression substitutions. Within the string, sequences of the form `\N` refer to the Nth capture group in the regex, and `\g<groupname>` refers to a named capture group with name `groupname`.
**Examples**
```julia-repl
julia> msg = "#Hello# from Julia";

julia> replace(msg, r"#(.+)# from (?<from>\w+)" => s"FROM: \g<from>; MESSAGE: \1")
"FROM: Julia; MESSAGE: Hello"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L598-L612)
```julia
@raw_str -> String
```


# [Strings](#lib-strings)
Create a raw string without interpolation and unescaping. The exception is that quotation marks still must be escaped. Backslashes escape both quotation marks and other backslashes, but only when a sequence of backslashes precedes a quote character. Thus, 2n backslashes followed by a quote encodes n backslashes and the end of the literal while 2n+1 backslashes followed by a quote encodes n backslashes followed by a quote character.
**Examples**
```julia-repl
julia> println(raw"\ $x")
\ $x

julia> println(raw"\"")
"

julia> println(raw"\\\"")
\"

julia> println(raw"\\x \\\"")
\\x \"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/io.jl#L585-L609)
```julia
@b_str
```
Create an immutable byte (`UInt8`) vector using string syntax.
**Examples**
```julia-repl
julia> v = b"12\x01\x02"
4-element Base.CodeUnits{UInt8, String}:
 0x31
 0x32
 0x01
 0x02

julia> v[2]
0x32
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/io.jl#L562-L579)
```julia
@html_str -> Docs.HTML
```
Create an `HTML` object from a literal string.
**Examples**
```julia-repl
julia> html"Julia"
HTML{String}("Julia")
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/utils.jl#L44-L54)
```julia
@text_str -> Docs.Text
```
Create a `Text` object from a literal string.
**Examples**
```julia-repl
julia> text"Julia"
Julia
```


# [Strings](#lib-strings)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/docs/utils.jl#L98-L108)
```julia
isvalid(value) -> Bool
```
Return `true` if the given value is valid for its type, which currently can be either `AbstractChar` or `String` or `SubString{String}`.
**Examples**
```julia-repl
julia> isvalid(Char(0xd800))
false

julia> isvalid(SubString(String(UInt8[0xfe,0x80,0x80,0x80,0x80,0x80]),1,2))
false

julia> isvalid(Char(0xd799))
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/unicode.jl#L13-L30)
```julia
isvalid(T, value) -> Bool
```
Return `true` if the given value is valid for that type. Types currently can be either `AbstractChar` or `String`. Values for `AbstractChar` can be of type `AbstractChar` or [`UInt32`](../numbers/#Core.UInt32). Values for `String` can be of that type, `SubString{String}`, `Vector{UInt8}`, or a contiguous subarray thereof.
**Examples**
```julia-repl
julia> isvalid(Char, 0xd800)
false

julia> isvalid(String, SubString("thisisvalid",1,5))
true

julia> isvalid(Char, 0xd799)
true
```
Support for subarray values was added in Julia 1.6.
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/unicode.jl#L33-L55)
```julia
isvalid(s::AbstractString, i::Integer) -> Bool
```


# [Strings](#lib-strings)
Predicate indicating whether the given index is the start of the encoding of a character in `s` or not. If `isvalid(s, i)` is true then `s[i]` will return the character whose encoding starts at that index, if it's false, then `s[i]` will raise an invalid index error or a bounds error depending on if `i` is in bounds. In order for `isvalid(s, i)` to be an O(1) function, the encoding of `s` must be [self-synchronizing](https://en.wikipedia.org/wiki/Self-synchronizing_code). This is a basic assumption of Julia's generic string support.
See also [`getindex`](../collections/#Base.getindex), [`iterate`](../collections/#Base.iterate), [`thisind`](#Base.thisind), [`nextind`](../arrays/#Base.nextind), [`prevind`](../arrays/#Base.prevind), [`length`](../collections/#Base.length).
**Examples**
```julia-repl
julia> str = "αβγdef";

julia> isvalid(str, 1)
true

julia> str[1]
'α': Unicode U+03B1 (category Ll: Letter, lowercase)

julia> isvalid(str, 2)
false

julia> str[2]
ERROR: StringIndexError: invalid index [2], valid nearby indices [1]=>'α', [3]=>'β'
Stacktrace:
[...]
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/strings/basic.jl#L108-L140)
```julia
match(r::Regex, s::AbstractString[, idx::Integer[, addopts]])
```


# [Strings](#lib-strings)
Search for the first match of the regular expression `r` in `s` and return a [`RegexMatch`](#Base.RegexMatch) object containing the match, or nothing if the match failed. The matching substring can be retrieved by accessing `m.match` and the captured sequences can be retrieved by accessing `m.captures` The optional `idx` argument specifies an index at which to start the search.
**Examples**
```julia-repl
julia> rx = r"a(.)a"
r"a(.)a"

julia> m = match(rx, "cabac")
RegexMatch("aba", 1="b")

julia> m.captures
1-element Vector{Union{Nothing, SubString{String}}}:
 "b"

julia> m.match
"aba"

julia> match(rx, "cabac", 3) === nothing
true
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L386-L412)
```julia
eachmatch(r::Regex, s::AbstractString; overlap::Bool=false)
```
Search for all matches of the regular expression `r` in `s` and return an iterator over the matches. If `overlap` is `true`, the matching sequences are allowed to overlap indices in the original string, otherwise they must be from distinct character ranges.
**Examples**
```julia-repl
julia> rx = r"a.a"
r"a.a"

julia> m = eachmatch(rx, "a1a2a3a")
Base.RegexMatchIterator{String}(r"a.a", "a1a2a3a", false)

julia> collect(m)
2-element Vector{RegexMatch}:
 RegexMatch("a1a")
 RegexMatch("a3a")

julia> collect(eachmatch(rx, "a1a2a3a", overlap = true))
3-element Vector{RegexMatch}:
 RegexMatch("a1a")
 RegexMatch("a2a")
 RegexMatch("a3a")
```


# [Strings](#lib-strings)
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L754-L780)
```julia
RegexMatch <: AbstractMatch
```
A type representing a single match to a [`Regex`](#Base.Regex) found in a string. Typically created from the [`match`](#Base.match) function.
The `match` field stores the substring of the entire matched string. The `captures` field stores the substrings for each capture group, indexed by number. To index by capture group name, the entire match object should be indexed instead, as shown in the examples. The location of the start of the match is stored in the `offset` field. The `offsets` field stores the locations of the start of each capture group, with 0 denoting a group that was not captured.
This type can be used as an iterator over the capture groups of the `Regex`, yielding the substrings captured in each group. Because of this, the captures of a match can be destructured. If a group was not captured, `nothing` will be yielded instead of a substring.
Methods that accept a `RegexMatch` object are defined for [`iterate`](../collections/#Base.iterate), [`length`](../collections/#Base.length), [`eltype`](../collections/#Base.eltype), [`keys`](#Base.keys-Tuple%7BRegexMatch%7D), [`haskey`](../collections/#Base.haskey), and [`getindex`](../collections/#Base.getindex), where keys are the the names or numbers of a capture group. See [`keys`](#Base.keys-Tuple%7BRegexMatch%7D) for more information.
**Examples**


# [Strings](#lib-strings)
```julia-repl
julia> m = match(r"(?<hour>\d+):(?<minute>\d+)(am|pm)?", "11:30 in the morning")
RegexMatch("11:30", hour="11", minute="30", 3=nothing)

julia> m.match
"11:30"

julia> m.captures
3-element Vector{Union{Nothing, SubString{String}}}:
 "11"
 "30"
 nothing

julia> m["minute"]
"30"

julia> hr, min, ampm = m; # destructure capture groups by iteration

julia> hr
"11"
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L173-L220)
```julia
keys(m::RegexMatch) -> Vector
```
Return a vector of keys for all capture groups of the underlying regex. A key is included even if the capture group fails to match. That is, `idx` will be in the return value even if `m[idx] == nothing`.
Unnamed capture groups will have integer keys corresponding to their index. Named capture groups will have string keys.
This method was added in Julia 1.7
**Examples**
```julia-repl
julia> keys(match(r"(?<hour>\d+):(?<minute>\d+)(am|pm)?", "11:30"))
3-element Vector{Any}:
  "hour"
  "minute"
 3
```
[source](https://github.com/JuliaLang/julia/blob/9615af0f269df4d371b8010e9507ed5bae86103b/base/regex.jl#L233-L254)
```julia
isless(a::AbstractString, b::AbstractString) -> Bool
```
Test whether string `a` comes before string `b` in alphabetical order (technically, in lexicographical order by Unicode code points).
**Examples**
```julia-repl
julia> isless("a", "b")
true

julia> isless("β", "α")
false

julia> isless("a", "a")
false
```