[gambit-list] API to parse floats in Scheme
Lassi Kortela
lassi at lassi.io
Wed May 12 15:43:16 EDT 2021
We are planning a simple SRFI to mae floats from integers (or from
strings), since that's useful when parsing any kind of text syntax that
has real numbers. The details are implementation-dependent and tricky to
get right.
Here's the spec we have so far: https://github.com/pre-srfi/make-float
The API is:
(inexact-real-from-strings int frac precision exp) -> real
(inexact-real-from-integers int frac frac-length precision exp) -> real
Example usage:
(inexact-real-from-strings "-123" "45" 'e "6") ; => -123.45e6
(inexact-real-from-integers -123 45 2 'e 6) ; => -123.45e6
The 2 in the last example means two decimal places. It's needed to
disambiguate between .6 .06 .006 .0006 etc.
There are both math and Scheme wizards on this list. Could someone
verify whether this is a sane design before we submit the SRFI draft?
It's been ok'd by one mathematician already so I'm hopeful :)
There's also an inverse API to serve as a backend for string formatting
packages:
(strings-from-inexact-real real frac-length) -> int; frac; exp
(integers-from-inexact-real real frac-length) -> int; frac; exp
More information about the Gambit-list
mailing list