Skip to content

Commit to a stable set of methods for writing floats (shortest, fixed, exp) #59763

@quinnj

Description

@quinnj

A large part of my original motivation of porting/implementing the ryu float -> string algorithm in Julia was to then be able to use it in various packages: CSV.jl, Parsers.jl, JSON.jl, etc. 6 years ago, it was a relatively simpler/looser world, so using the Ryu.writeshortest, Ryu.writefixed, and Ryu.writeexp functions directly seemed fine.

We're now trying to be better package developer citizens and not rely on Base internals, which may change, and thus break future package versions.

The proposal here would be committing to a public API around "lower level" float -> string writing, specifically around being able to write to an AbstractVector{UInt8} + pos::Int directly.

  • writeshortest, writefixed, and writeexp; basically matching what we have today, just not including the possibly not-future-proof Ryu module prefix
  • Make Printf.format(buf, pos, ::Printf.Format, args...) part of the Printf public API. It's not specifically documented as part of the public API, and I think it carries a bit of overhead over what Ryu.writeX do (well, obviously, since Printf uses those functions directly). The advantage is the functionality is already there and namedspaced in Printf already w/ the Printf.Format being a pretty common/standard convention for specifying the "api" of how to write floats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.featureIndicates new feature / enhancement requests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions