diff --git a/base/grisu/grisu.jl b/base/grisu/grisu.jl index c46c4f8632b76..b1082106c63a6 100644 --- a/base/grisu/grisu.jl +++ b/base/grisu/grisu.jl @@ -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