Skip to content

Commit

Permalink
update docs, use new markdown syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Aug 16, 2016
1 parent f6e9bdf commit 28eeed8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
27 changes: 14 additions & 13 deletions base/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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)
Expand Down
28 changes: 27 additions & 1 deletion doc/stdlib/numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 28eeed8

Please sign in to comment.