set_rounding

..  set_rounding(T, mode)

Set the rounding mode of floating point type ``T``, controlling the
rounding of basic arithmetic functions (:func:`+`, :func:`-`, :func:`*`,
:func:`/` and :func:`sqrt`) and type conversion.

Note that this may affect other types, for instance changing the rounding
mode of ``Float64`` will change the rounding mode of ``Float32``. See
``get_rounding`` for available modes

Examples

The set_rounding(T, mode) function in Julia sets the rounding mode of the floating-point type T, which controls the rounding behavior of basic arithmetic functions like +, -, *, /, and sqrt, as well as type conversions. It's important to note that changing the rounding mode of one floating-point type may affect other related types.

Here are some examples of how to use the set_rounding function in Julia:

  1. Set the rounding mode for Float64:

    julia> set_rounding(Float64, RoundNearest)

    This sets the rounding mode of Float64 to "RoundNearest".

  2. Set the rounding mode for Float32:

    julia> set_rounding(Float32, RoundToZero)

    This sets the rounding mode of Float32 to "RoundToZero".

  3. Get the rounding mode for a specific floating-point type:
    julia> get_rounding(Float64)
    RoundNearest

    This example retrieves the current rounding mode for Float64.

Please note that the available rounding modes can be found using the get_rounding function, as mentioned in the documentation snippet.

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.

*Required Field
Details

Checking you are not a robot: