Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use native Julia code in round example #46841

Merged
merged 1 commit into from
Sep 20, 2022
Merged

use native Julia code in round example #46841

merged 1 commit into from
Sep 20, 2022

Conversation

udohjeremiah
Copy link
Contributor

This !!! note section on round introduces a concept or function not native to Julia code, where a better Julia solution could have been used:

  │ Note
  │
  │  Rounding to specified digits in bases other than 2 can be
  │  inexact when operating on binary floating point numbers. For
  │  example, the Float64 value represented by 1.15 is actually less
  │  than 1.15, yet will be rounded to 1.2. For example:
  |
  │  julia> @sprintf "%.20f" x
  │  "1.14999999999999991118"

The @sprintf function introduced there complicates things for some number of reasons:

  • Julia users not acquainted with the Printf module or C printf style would not get the understanding of what that part is trying to do or explain. Sure they can lookup @sprintf in the docs, but then they have to figure out what the %.20f does and all that stuffs, just to understand the example.
  • Trying to replicate the example fails because it does not show where @sprintf comes from (i.e. no using Printf is shown there, so users know its exported).

Just to understand an example, and then one has to figure out all that sutff - Huh, I think its uncalled for. Why not just use Julia's big to show what's happening there, its same with the @sprintf (just the difference being that @sprintf shows the results in 20 digits after decimal point):

julia> using Printf

julia> x = 1.15
1.15

julia> big(x)
1.149999999999999911182158029987476766109466552734375

julia> @sprintf "%.20f" x
"1.14999999999999991118"

@udohjeremiah udohjeremiah added the docs This change adds or pertains to documentation label Sep 20, 2022
@rfourquet rfourquet added the maths Mathematical functions label Sep 20, 2022
@oscardssmith oscardssmith merged commit 276af84 into JuliaLang:master Sep 20, 2022
@udohjeremiah udohjeremiah deleted the patch-20 branch September 20, 2022 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants