[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Portable dtoa.c



On 08/02/16 12:34, Ole Streicher wrote:
> I am working to get my "pyephem" package done for all available
> (official and unofficial) ports. The major problem here is that it uses
> "ascii_strtod() from the file "dtoa.c" by David M. Gray [1] that is
> machine dependent.

>From the name, is it an extension for Python?

Python has its own version of dtoa, crediting David M. Gay (I assume
this is the same author you meant):

https://sources.debian.net/src/python3.5/3.5.1-5/Python/dtoa.c/

so you might be able to call into libpython instead of reinventing it?

Failing that, GLib has g_ascii_strtod(), which looks machine-independent
and reasonably separable from the rest of GLib, and is much, much
simpler than the one in Python - it might be somewhat slower, but I
doubt that matters much on current hardware. In particular, on systems
that support it (which should include all glibc systems like Debian, as
far as I can see), it uses strtod_l() in the C locale instead of doing
the parsing itself.

As a general rule of thumb, good places to find implementations of
useful but not-necessarily-portable functions like this are "make C more
portable/pleasant" libraries like GLib, and language runtimes like
Python :-)

    S


Reply to: