precision
precision(num::AbstractFloat)
Get the precision of a floating point number, as defined by the effective number of bits in the mantissa.
Examples
In the Julia programming language, the function precision(num::AbstractFloat)
is used to determine the precision of a floating-point number. It returns the effective number of bits in the mantissa.
julia> precision(0.123)
53
Here are some common examples of how to use the precision
function:
-
Get the precision of a Float64 number:
julia> num = 3.14159; julia> precision(num) 53
In this example, the
precision
function is used to determine the precision of thenum
variable, which is aFloat64
number. -
Check the precision of a Float32 number:
julia> num = Float32(2.71828); julia> precision(num) 24
Here, the
precision
function is applied to thenum
variable, which is aFloat32
number, to obtain its precision. - Calculate the precision of a custom floating-point type:
julia> using DecFP julia> num = Dec64("0.123456789"); julia> precision(num) 34
This example showcases the usage of the
precision
function with a custom floating-point type (Dec64
from theDecFP
package). It returns the precision of thenum
variable.
It's important to note that the precision
function only applies to floating-point numbers (AbstractFloat
types). Using it with other data types will result in a method error.
See Also
cmp, float, get_bigfloat_precision, get_rounding, get_zero_subnormals, isapprox, maxintfloat, mod2pi, nextfloat, precision, prevfloat, rationalize, round, set_bigfloat_precision, set_rounding, set_zero_subnormals, significand, with_bigfloat_precision, with_rounding,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.