Skip to content

Commit 5f74d16

Browse files
simonbyrnestevengj
authored andcommitted
Add accuracy note for 2-arg log (#18360)
* Add accuracy note for 2-arg log Addresses #18298. * update based on comments
1 parent 442af7b commit 5f74d16

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

base/math.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ julia> log(4,8)
161161
julia> log(4,2)
162162
0.5
163163
```
164+
165+
!!! note
166+
If `b` is a power of 2 or 10, `log2` or `log10` should be used, as these will
167+
typically be faster and more accurate. For example,
168+
169+
```jldoctest
170+
julia> log(100,1000000)
171+
2.9999999999999996
172+
173+
julia> log10(1000000)/2
174+
3.0
175+
```
164176
"""
165177
log(b::Number, x::Number) = log(promote(b,x)...)
166178

doc/stdlib/math.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ Mathematical Functions
835835
julia> log(4,2)
836836
0.5
837837

838+
.. note::
839+
If ``b`` is a power of 2 or 10, ``log2`` or ``log10`` should be used, as these will typically be faster and more accurate. For example,
840+
841+
.. doctest::
842+
843+
julia> log(100,1000000)
844+
2.9999999999999996
845+
846+
julia> log10(1000000)/2
847+
3.0
848+
849+
838850
.. function:: log2(x)
839851

840852
.. Docstring generated from Julia source

0 commit comments

Comments
 (0)