From 28eeed85bdcc3b818b53692f07b5ee1d64b87fa4 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Tue, 16 Aug 2016 16:30:46 +0100 Subject: [PATCH] update docs, use new markdown syntax --- base/rounding.jl | 27 ++++++++++++++------------- doc/stdlib/numbers.rst | 28 +++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/base/rounding.jl b/base/rounding.jl index 4571419584c05..76e3490b78bc7 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -109,6 +109,8 @@ Note that this may affect other types, for instance changing the rounding mode o will change the rounding mode of `Float32`. See [`RoundingMode`](:obj:`RoundingMode`) for available modes. +!!! warning + This feature is still experimental, and may give unexpected or incorrect values. """ setrounding(T::Type, mode) @@ -120,8 +122,6 @@ arithmetic functions ([`+`](:func:`+`), [`-`](:func:`-`), [`*`](:func:`*`), [`/` and [`sqrt`](:func:`sqrt`)) and type conversion. See [`RoundingMode`](:obj:`RoundingMode`) for available modes. - -**Warning**: This feature is still experimental, and may give unexpected or incorrect values. """ :rounding @@ -144,21 +144,22 @@ equivalent to: See [`RoundingMode`](:obj:`RoundingMode`) for available rounding modes. -**Warning**: This feature is still experimental, and may give unexpected or incorrect values. A known problem is the interaction with compiler optimisations, e.g. +!!! warning + This feature is still experimental, and may give unexpected or incorrect values. A known problem is the interaction with compiler optimisations, e.g. - julia> setrounding(Float64,RoundDown) do - 1.1 + 0.1 - end - 1.2000000000000002 + julia> setrounding(Float64,RoundDown) do + 1.1 + 0.1 + end + 1.2000000000000002 -Here the compiler is *constant folding*, that is evaluating a known constant expression at compile time, however the rounding mode is only changed at runtime, so this is not reflected in the function result. This can be avoided by moving constants outside the expression, e.g. + Here the compiler is *constant folding*, that is evaluating a known constant expression at compile time, however the rounding mode is only changed at runtime, so this is not reflected in the function result. This can be avoided by moving constants outside the expression, e.g. - julia> x = 1.1; y = 0.1; + julia> x = 1.1; y = 0.1; - julia> setrounding(Float64,RoundDown) do - x + y - end - 1.2 + julia> setrounding(Float64,RoundDown) do + x + y + end + 1.2 """ function setrounding{T}(f::Function, ::Type{T}, rounding::RoundingMode) old_rounding_raw = rounding_raw(T) diff --git a/doc/stdlib/numbers.rst b/doc/stdlib/numbers.rst index ae1d47fa34c5f..1d89e90c5db58 100644 --- a/doc/stdlib/numbers.rst +++ b/doc/stdlib/numbers.rst @@ -371,10 +371,14 @@ General Number Functions and Constants .. Docstring generated from Julia source - 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. + 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. Other numerical functions may give incorrect or invalid values when using rounding modes other than the default ``RoundNearest``\ . Note that this may affect other types, for instance changing the rounding mode of ``Float64`` will change the rounding mode of ``Float32``\ . See :obj:`RoundingMode` for available modes. + .. warning:: + This feature is still experimental, and may give unexpected or incorrect values. + + .. function:: setrounding(f::Function, T, mode) .. Docstring generated from Julia source @@ -390,6 +394,28 @@ General Number Functions and Constants See :obj:`RoundingMode` for available rounding modes. + .. warning:: + This feature is still experimental, and may give unexpected or incorrect values. A known problem is the interaction with compiler optimisations, e.g. + + .. code-block:: julia + + julia> setrounding(Float64,RoundDown) do + 1.1 + 0.1 + end + 1.2000000000000002 + + Here the compiler is *constant folding*, that is evaluating a known constant expression at compile time, however the rounding mode is only changed at runtime, so this is not reflected in the function result. This can be avoided by moving constants outside the expression, e.g. + + .. code-block:: julia + + julia> x = 1.1; y = 0.1; + + julia> setrounding(Float64,RoundDown) do + x + y + end + 1.2 + + .. function:: get_zero_subnormals() -> Bool .. Docstring generated from Julia source