BigFloat
.. BigFloat(x)
Create an arbitrary precision floating point number. ``x`` may be
an ``Integer``, a ``Float64`` or a ``BigInt``. The
usual mathematical operators are defined for this type, and results
are promoted to a ``BigFloat``.
Note that because decimal literals are converted to floating point numbers
when parsed, ``BigFloat(2.1)`` may not yield what you expect. You may instead
prefer to initialize constants from strings via :func:`parse`, or using the
``big`` string literal.
.. doctest::
julia> BigFloat(2.1)
2.100000000000000088817841970012523233890533447265625000000000000000000000000000
julia> big"2.1"
2.099999999999999999999999999999999999999999999999999999999999999999999999999986
Examples
The BigFloat(x)
function in Julia is used to create an arbitrary precision floating-point number. The input x
can be a NaN
, an Integer
, a Float64
, or a BigInt
. Mathematical operators are defined for this type, and results are promoted to a BigFloat
.
Here are some examples of how to use the BigFloat
function:
-
Create a
BigFloat
from anInteger
:julia> BigFloat(10) 1.000000000000000000000000000000000000000000000000000000000000000000000000000000
-
Create a
BigFloat
from aFloat64
:julia> BigFloat(3.14) 3.140000000000000124344978758017532527446746826171875000000000000000000000000000
- Create a
BigFloat
from aBigInt
:julia> BigFloat(big(123456789)) 1.234567890000000000000000000000000000000000000000000000000000000000000000000000e+08
It's important to note that when using decimal literals, they are converted to floating-point numbers when parsed. This can result in some loss of precision. To ensure precise initialization, you can use the parse
function or the big
string literal.
Here is an example using parse
to initialize from a string:
julia> parse(BigFloat, "2.1")
2.099999999999999999999999999999999999999999999999999999999999999999999999999999
And here is an example using the big
string literal:
julia> big"2.1"
2.099999999999999999999999999999999999999999999999999999999
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.