Skip to content

Commit

Permalink
document Grisu (#27808)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne authored Jul 2, 2018
1 parent 80db579 commit 72bfe8b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions base/grisu/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,28 @@ function __init__()
Threads.resize_nthreads!(BIGNUMSs)
end

"""
(len, point, neg) = Grisu.grisu(v::AbstractFloat, mode, requested_digits,
buffer=DIGITSs[Threads.threadid()], bignums=BIGNUMSs[Threads.threadid()])
Convert the number `v` to decimal using the Grisu algorithm.
`mode` can be one of:
- `Grisu.SHORTEST`: convert to the shortest decimal representation which can be "round-tripped" back to `v`.
- `Grisu.FIXED`: round to `requested_digits` digits.
- `Grisu.PRECISION`: round to `requested_digits` significant digits.
The characters are written as bytes to `buffer`, with a terminating NUL byte, and `bignums` are used internally as part of the correction step.
The returned tuple contains:
- `len`: the number of digits written to `buffer` (excluding NUL)
- `point`: the location of the radix point relative to the start of the array (e.g. if
`point == 3`, then the radix point should be inserted between the 3rd and 4th
digit). Note that this can be negative (for very small values), or greater than `len`
(for very large values).
- `neg`: the signbit of `v` (see [`signbit`](@ref)).
"""
function grisu(v::AbstractFloat,mode,requested_digits,buffer=DIGITSs[Threads.threadid()],bignums=BIGNUMSs[Threads.threadid()])
if signbit(v)
neg = true
Expand Down

0 comments on commit 72bfe8b

Please sign in to comment.