Numbers
标准数值类型
抽象数值类型
Core.Number — Type
1. Number
Abstract supertype for all number types.
Core.Real — Type
1. Real <: Number
Abstract supertype for all real numbers.
Core.AbstractFloat — Type
1. AbstractFloat <: Real
Abstract supertype for all floating point numbers.
Core.Integer — Type
1. Integer <: Real
Abstract supertype for all integers.
Core.Signed — Type
1. Signed <: Integer
Abstract supertype for all signed integers.
Core.Unsigned — Type
1. Unsigned <: Integer
Abstract supertype for all unsigned integers.
Base.AbstractIrrational — Type
1. 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 to equal that of the corresponding Rational.
具象数值类型
Core.Float16 — Type
1. Float16 <: AbstractFloat
16-bit floating point number type (IEEE 754 standard).
Binary format: 1 sign, 5 exponent, 10 fraction bits.
Core.Float32 — Type
1. Float32 <: AbstractFloat
32-bit floating point number type (IEEE 754 standard).
Binary format: 1 sign, 8 exponent, 23 fraction bits.
Core.Float64 — Type
1. Float64 <: AbstractFloat
64-bit floating point number type (IEEE 754 standard).
Binary format: 1 sign, 11 exponent, 52 fraction bits.
Base.MPFR.BigFloat — Type
1. BigFloat <: AbstractFloat
Arbitrary precision floating point number type.
Core.Bool — Type
1. 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”:
1. julia> false == 0
2. true
4. julia> true == 1
5. true
7. julia> 0 * NaN
8. NaN
10. julia> false * NaN
11. 0.0
See also: digits, iszero, NaN.
Core.Int8 — Type
1. Int8 <: Signed
8-bit signed integer type.
Core.UInt8 — Type
1. UInt8 <: Unsigned
8-bit unsigned integer type.
Core.Int16 — Type
1. Int16 <: Signed
16-bit signed integer type.
Core.UInt16 — Type
1. UInt16 <: Unsigned
16-bit unsigned integer type.
Core.Int32 — Type
1. Int32 <: Signed
32-bit signed integer type.
Core.UInt32 — Type
1. UInt32 <: Unsigned
32-bit unsigned integer type.
Core.Int64 — Type
1. Int64 <: Signed
64-bit signed integer type.
Core.UInt64 — Type
1. UInt64 <: Unsigned
64-bit unsigned integer type.
Core.Int128 — Type
1. Int128 <: Signed
128-bit signed integer type.
Core.UInt128 — Type
1. UInt128 <: Unsigned
128-bit unsigned integer type.
Base.GMP.BigInt — Type
1. BigInt <: Signed
Arbitrary precision integer type.
Base.Complex — Type
1. 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, complex, real.
Base.Rational — Type
1. Rational{T<:Integer} <: Real
Rational number type, with numerator and denominator of type T. Rationals are checked for overflow.
Base.Irrational — Type
1. Irrational{sym} <: AbstractIrrational
Number type representing an exact irrational value denoted by the symbol sym, such as π, ℯ and γ.
See also [@irrational], AbstractIrrational.
数据格式
Base.digits — Function
1. 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=1:length(digits)).
See also ndigits, digits!, and for base 2 also bitstring, count_ones.
Examples
1. julia> digits(10)
2. 2-element Vector{Int64}:
3. 0
4. 1
6. julia> digits(10, base = 2)
7. 4-element Vector{Int64}:
8. 0
9. 1
10. 0
11. 1
13. julia> digits(-256, base = 10, pad = 5)
14. 5-element Vector{Int64}:
15. -6
16. -5
17. -2
18. 0
19. 0
21. julia> n = rand(-999:999);
23. julia> n == evalpoly(13, digits(n, base = 13))
24. true
Base.digits! — Function
1. 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
1. julia> digits!([2,2,2,2], 10, base = 2)
2. 4-element Vector{Int64}:
3. 0
4. 1
5. 0
6. 1
8. julia> digits!([2,2,2,2,2,2], 10, base = 2)
9. 6-element Vector{Int64}:
10. 0
11. 1
12. 0
13. 1
14. 0
15. 0
Base.bitstring — Function
1. bitstring(n)
A string giving the literal bit representation of a number.
See also count_ones, count_zeros, digits.
Examples
1. julia> bitstring(Int32(4))
2. "00000000000000000000000000000100"
4. julia> bitstring(2.2)
5. "0100000000000001100110011001100110011001100110011001100110011010"
Base.parse — Function
1. parse(::Type{Platform}, triplet::AbstractString)
Parses a string platform triplet back into a Platform object.
1. 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.
Julia 1.1
parse(Bool, str) requires at least Julia 1.1.
Examples
1. julia> parse(Int, "1234")
2. 1234
4. julia> parse(Int, "1234", base = 5)
5. 194
7. julia> parse(Int, "afc", base = 16)
8. 2812
10. julia> parse(Float64, "1.2e-3")
11. 0.0012
13. julia> parse(Complex{Float64}, "3.2e-1 + 4.5im")
14. 0.32 + 4.5im
Base.tryparse — Function
1. tryparse(type, str; base)
Like parse, but returns either a value of the requested type, or nothing if the string does not contain a valid number.
Base.big — Function
1. big(x)
Convert a number to a maximum precision representation (typically BigInt or BigFloat). See BigFloat for information about some pitfalls with floating-point numbers.
Base.signed — Function
1. signed(T::Integer)
Convert an integer bitstype to the signed type of the same size.
Examples
1. julia> signed(UInt16)
2. Int16
3. julia> signed(UInt64)
4. Int64
1. 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, sign, signbit.
Base.unsigned — Function
1. unsigned(T::Integer)
Convert an integer bitstype to the unsigned type of the same size.
Examples
1. julia> unsigned(Int16)
2. UInt16
3. julia> unsigned(UInt64)
4. UInt64
Base.float — Method
1. float(x)
Convert a number or array to a floating point data type.
See also: complex, oftype, convert.
Examples
1. julia> float(1:1000)
2. 1.0:1.0:1000.0
4. julia> float(typemax(Int32))
5. 2.147483647e9
Base.Math.significand — Function
1. significand(x)
Extract the significand(s) (a.k.a. mantissa), in binary representation, of a floating-point number. If x is a non-zero finite number, then the result will be a number of the same type on the interval $[1,2)$. Otherwise x is returned.
Examples
1. julia> significand(15.2)/15.2
2. 0.125
4. julia> significand(15.2)*8
5. 15.2
Base.Math.exponent — Function
1. exponent(x::AbstractFloat) -> Int
Get the exponent of a normalized floating-point number. Returns the largest integer y such that 2^y ≤ abs(x).
Examples
1. julia> exponent(6.5)
2. 2
4. julia> exponent(16.0)
5. 4
Base.complex — Method
1. complex(r, [i])
Convert real numbers or arrays to complex. i defaults to zero.
Examples
1. julia> complex(7)
2. 7 + 0im
4. julia> complex([1, 2, 3])
5. 3-element Vector{Complex{Int64}}:
6. 1 + 0im
7. 2 + 0im
8. 3 + 0im
Base.bswap — Function
1. bswap(n)
Reverse the byte order of n.
(See also ntoh and hton to convert between the current native byte order and big-endian order.)
Examples
1. julia> a = bswap(0x10203040)
2. 0x40302010
4. julia> bswap(a)
5. 0x10203040
7. julia> string(1, base = 2)
8. "1"
10. julia> string(bswap(1), base = 2)
11. "100000000000000000000000000000000000000000000000000000000"
Base.hex2bytes — Function
1. 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! for an in-place version, and bytes2hex for the inverse.
Julia 1.7
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
1. julia> s = string(12345, base = 16)
2. "3039"
4. julia> hex2bytes(s)
5. 2-element Vector{UInt8}:
6. 0x30
7. 0x39
9. julia> a = b"01abEF"
10. 6-element Base.CodeUnits{UInt8, String}:
11. 0x30
12. 0x31
13. 0x61
14. 0x62
15. 0x45
16. 0x46
18. julia> hex2bytes(a)
19. 3-element Vector{UInt8}:
20. 0x01
21. 0xab
22. 0xef
Base.hex2bytes! — Function
1. hex2bytes!(dest::AbstractVector{UInt8}, itr)
Convert an iterable itr of bytes representing a hexadecimal string to its binary representation, similar to hex2bytes except that the output is written in-place to dest. The length of dest must be half the length of itr.
Julia 1.7
Calling hex2bytes! with iterators producing UInt8 requires version 1.7. In earlier versions, you can collect the iterable before calling instead.
Base.bytes2hex — Function
1. bytes2hex(itr) -> String
2. 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.
Julia 1.7
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
1. julia> a = string(12345, base = 16)
2. "3039"
4. julia> b = hex2bytes(a)
5. 2-element Vector{UInt8}:
6. 0x30
7. 0x39
9. julia> bytes2hex(b)
10. "3039"
常用数值函数和常量
Base.one — Function
1. one(x)
2. 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 instead.
See also the identity function, and I in LinearAlgebra for the identity matrix.
Examples
1. julia> one(3.7)
2. 1.0
4. julia> one(Int)
5. 1
7. julia> import Dates; one(Dates.Day(1))
8. 1
Base.oneunit — Function
1. oneunit(x::T)
2. oneunit(T::Type)
Returns T(one(x)), where T is either the type of the argument or (if a type is passed) the argument. This differs from one for dimensionful quantities: one is dimensionless (a multiplicative identity) while oneunit is dimensionful (of the same type as x, or of type T).
Examples
1. julia> oneunit(3.7)
2. 1.0
4. julia> import Dates; oneunit(Dates.Day)
5. 1 day
Base.zero — Function
1. zero(x)
2. zero(::Type)
Get the additive identity element for the type of x (x can also specify the type itself).
See also iszero, one, oneunit, oftype.
Examples
1. julia> zero(1)
2. 0
4. julia> zero(big"2.0")
5. 0.0
7. julia> zero(rand(2,2))
8. 2×2 Matrix{Float64}:
9. 0.0 0.0
10. 0.0 0.0
Base.im — Constant
1. im
The imaginary unit.
See also: imag, angle, complex.
Examples
1. julia> im * im
2. -1 + 0im
4. julia> (2.0 + 3im)^2
5. -5.0 + 12.0im
Base.MathConstants.pi — Constant
1. π
2. pi
The constant pi.
Unicode π can be typed by writing \pi then pressing tab in the Julia REPL, and in many editors.
See also: sinpi, sincospi, deg2rad.
Examples
1. julia> pi
2. π = 3.1415926535897...
4. julia> 1/2pi
5. 0.15915494309189535
Base.MathConstants.ℯ — Constant
1. ℯ
2. e
The constant ℯ.
Unicode ℯ can be typed by writing \euler and pressing tab in the Julia REPL, and in many editors.
Examples
1. julia> ℯ
2. ℯ = 2.7182818284590...
4. julia> log(ℯ)
5. 1
7. julia> ℯ^(im)π ≈ -1
8. true
Base.MathConstants.catalan — Constant
1. catalan
Catalan’s constant.
Examples
1. julia> Base.MathConstants.catalan
2. catalan = 0.9159655941772...
4. julia> sum(log(x)/(1+x^2) for x in 1:0.01:10^6) * 0.01
5. 0.9159466120554123
Base.MathConstants.eulergamma — Constant
1. γ
2. eulergamma
Euler’s constant.
Examples
1. julia> Base.MathConstants.eulergamma
2. γ = 0.5772156649015...
4. julia> dx = 10^-6;
6. julia> sum(-exp(-x) * log(x) for x in dx:dx:100) * dx
7. 0.5772078382499134
Base.MathConstants.golden — Constant
1. φ
2. golden
The golden ratio.
Examples
1. julia> Base.MathConstants.golden
2. φ = 1.6180339887498...
4. julia> (2ans - 1)^2 ≈ 5
5. true
Base.Inf — Constant
1. Inf, Inf64
Positive infinity of type Float64.
See also: isfinite, typemax, NaN, Inf32.
Examples
1. julia> π/0
2. Inf
4. julia> +1.0 / -0.0
5. -Inf
7. julia> ℯ^-Inf
8. 0.0
Base.Inf32 — Constant
1. Inf32
Positive infinity of type Float32.
Base.Inf16 — Constant
1. Inf16
Positive infinity of type Float16.
Base.NaN — Constant
1. NaN, NaN64
A not-a-number value of type Float64.
See also: isnan, missing, NaN32, Inf.
Examples
1. julia> 0/0
2. NaN
4. julia> Inf - Inf
5. NaN
7. julia> NaN == NaN, isequal(NaN, NaN), NaN === NaN
8. (false, true, true)
Base.NaN32 — Constant
1. NaN32
A not-a-number value of type Float32.
Base.NaN16 — Constant
1. NaN16
A not-a-number value of type Float16.
Base.issubnormal — Function
1. issubnormal(f) -> Bool
Test whether a floating point number is subnormal.
Base.isfinite — Function
1. isfinite(f) -> Bool
Test whether a number is finite.
Examples
1. julia> isfinite(5)
2. true
4. julia> isfinite(NaN32)
5. false
Base.isinf — Function
1. isinf(f) -> Bool
Test whether a number is infinite.
See also: Inf, iszero, isfinite, isnan.
Base.isnan — Function
1. isnan(f) -> Bool
Test whether a number value is a NaN, an indeterminate value which is neither an infinity nor a finite number (“not a number”).
See also: iszero, isone, isinf, ismissing.
Base.iszero — Function
1. 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, isinteger, isfinite, isnan.
Examples
1. julia> iszero(0.0)
2. true
4. julia> iszero([1, 9, 0])
5. false
7. julia> iszero([false, 0, 0])
8. true
Base.isone — Function
1. isone(x)
Return true if x == one(x); if x is an array, this checks whether x is an identity matrix.
Examples
1. julia> isone(1.0)
2. true
4. julia> isone([1 0; 0 2])
5. false
7. julia> isone([1 0; 0 true])
8. true
Base.nextfloat — Function
1. nextfloat(x::AbstractFloat, n::Integer)
The result of n iterative applications of nextfloat to x if n >= 0, or -n applications of prevfloat if n < 0.
1. 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, eps, issubnormal.
Base.prevfloat — Function
1. prevfloat(x::AbstractFloat, n::Integer)
The result of n iterative applications of prevfloat to x if n >= 0, or -n applications of nextfloat if n < 0.
1. 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.
Base.isinteger — Function
1. isinteger(x) -> Bool
Test whether x is numerically equal to some integer.
Examples
1. julia> isinteger(4.0)
2. true
Base.isreal — Function
1. isreal(x) -> Bool
Test whether x or all its elements are numerically equal to some real number including infinities and NaNs. isreal(x) is true if isequal(x, real(x)) is true.
Examples
1. julia> isreal(5.)
2. true
4. julia> isreal(Inf + 0im)
5. true
7. julia> isreal([4.; complex(0,1)])
8. false
Core.Float32 — Method
1. Float32(x [, mode::RoundingMode])
Create a Float32 from x. If x is not exactly representable then mode determines how x is rounded.
Examples
1. julia> Float32(1/3, RoundDown)
2. 0.3333333f0
4. julia> Float32(1/3, RoundUp)
5. 0.33333334f0
See RoundingMode for available rounding modes.
Core.Float64 — Method
1. Float64(x [, mode::RoundingMode])
Create a Float64 from x. If x is not exactly representable then mode determines how x is rounded.
Examples
1. julia> Float64(pi, RoundDown)
2. 3.141592653589793
4. julia> Float64(pi, RoundUp)
5. 3.1415926535897936
See RoundingMode for available rounding modes.
Base.Rounding.rounding — Function
1. rounding(T)
Get the current floating point rounding mode for type T, controlling the rounding of basic arithmetic functions (+, -, *, / and sqrt) and type conversion.
See RoundingMode for available modes.
Base.Rounding.setrounding — Method
1. setrounding(T, mode)
Set the rounding mode of floating point type T, controlling the rounding of basic arithmetic functions (+, -, *, / and sqrt) and type conversion. Other numerical functions may give incorrect or invalid values when using rounding modes other than the default RoundNearest.
Note that this is currently only supported for T == BigFloat.
Warning
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.
Base.Rounding.setrounding — Method
1. setrounding(f::Function, T, mode)
Change the rounding mode of floating point type T for the duration of f. It is logically equivalent to:
1. old = rounding(T)
2. setrounding(T, mode)
3. f()
4. setrounding(T, old)
See RoundingMode for available rounding modes.
Base.Rounding.get_zero_subnormals — Function
1. 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.
Warning
This function only affects the current thread.
Base.Rounding.set_zero_subnormals — Function
1. 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).
Warning
This function only affects the current thread.
整型
Base.count_ones — Function
1. count_ones(x::Integer) -> Integer
Number of ones in the binary representation of x.
Examples
1. julia> count_ones(7)
2. 3
4. julia> count_ones(Int32(-1))
5. 32
Base.count_zeros — Function
1. count_zeros(x::Integer) -> Integer
Number of zeros in the binary representation of x.
Examples
1. julia> count_zeros(Int32(2 ^ 16 - 1))
2. 16
4. julia> count_zeros(-1)
5. 0
Base.leading_zeros — Function
1. leading_zeros(x::Integer) -> Integer
Number of zeros leading the binary representation of x.
Examples
1. julia> leading_zeros(Int32(1))
2. 31
Base.leading_ones — Function
1. leading_ones(x::Integer) -> Integer
Number of ones leading the binary representation of x.
Examples
1. julia> leading_ones(UInt32(2 ^ 32 - 2))
2. 31
Base.trailing_zeros — Function
1. trailing_zeros(x::Integer) -> Integer
Number of zeros trailing the binary representation of x.
Examples
1. julia> trailing_zeros(2)
2. 1
Base.trailing_ones — Function
1. trailing_ones(x::Integer) -> Integer
Number of ones trailing the binary representation of x.
Examples
1. julia> trailing_ones(3)
2. 2
Base.isodd — Function
1. isodd(x::Number) -> Bool
Return true if x is an odd integer (that is, an integer not divisible by 2), and false otherwise.
Julia 1.7
Non-Integer arguments require Julia 1.7 or later.
Examples
1. julia> isodd(9)
2. true
4. julia> isodd(10)
5. false
Base.iseven — Function
1. iseven(x::Number) -> Bool
Return true if x is an even integer (that is, an integer divisible by 2), and false otherwise.
Julia 1.7
Non-Integer arguments require Julia 1.7 or later.
Examples
1. julia> iseven(9)
2. false
4. julia> iseven(10)
5. true
Core.@int128_str — Macro
1. @int128_str str
2. @int128_str(str)
@int128_str parses a string into a Int128 Throws an ArgumentError if the string is not a valid integer
Core.@uint128_str — Macro
1. @uint128_str str
2. @uint128_str(str)
@uint128_str parses a string into a UInt128 Throws an ArgumentError if the string is not a valid integer
BigFloats and BigInts
The BigFloat and BigInt types implements arbitrary-precision floating point and integer arithmetic, respectively. For BigFloat the GNU MPFR library is used, and for BigInt the GNU Multiple Precision Arithmetic Library (GMP) is used.
Base.MPFR.BigFloat — Method
1. 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. This is provided for convenience since decimal literals are converted to Float64 when parsed, so BigFloat(2.1) may not yield what you expect.
See also:
- @big_str
- rounding and setrounding
- precision and setprecision
Julia 1.1
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
1. julia> BigFloat(2.1) # 2.1 here is a Float64
2. 2.100000000000000088817841970012523233890533447265625
4. julia> BigFloat("2.1") # the closest BigFloat to 2.1
5. 2.099999999999999999999999999999999999999999999999999999999999999999999999999986
7. julia> BigFloat("2.1", RoundUp)
8. 2.100000000000000000000000000000000000000000000000000000000000000000000000000021
10. julia> BigFloat("2.1", RoundUp, precision=128)
11. 2.100000000000000000000000000000000000007
Base.precision — Function
1. precision(num::AbstractFloat)
Get the precision of a floating point number, as defined by the effective number of bits in the significand.
Base.precision — Method
1. precision(BigFloat)
Get the precision (in bits) currently used for BigFloat arithmetic.
Base.MPFR.setprecision — Function
1. setprecision([T=BigFloat,] precision::Int)
Set the precision (in bits) to be used for T arithmetic.
Warning
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.
1. setprecision(f::Function, [T=BigFloat,] precision::Integer)
Change the T arithmetic precision (in bits) for the duration of f. It is logically equivalent to:
1. old = precision(BigFloat)
2. setprecision(BigFloat, precision)
3. f()
4. setprecision(BigFloat, old)
Often used as setprecision(T, precision) do ... end
Note: nextfloat(), prevfloat() do not use the precision mentioned by setprecision
Base.GMP.BigInt — Method
1. 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.
Instances can be constructed from strings via parse, or using the big string literal.
Examples
1. julia> parse(BigInt, "42")
2. 42
4. julia> big"313"
5. 313
7. julia> BigInt(10)^19
8. 10000000000000000000
Core.@big_str — Macro
1. @big_str str
2. @big_str(str)
Parse a string into a BigInt or BigFloat, and throw an ArgumentError if the string is not a valid number. For integers _ is allowed in the string as a separator.
Examples
1. julia> big"123_456"
2. 123456
4. julia> big"7891.5"
5. 7891.5
