Hi Greg, This is quite impressive, particularly for a first time Lisper. Great job!
I haven't tested it, but the code looks good. Thanks for the contribution. AW *https://aw.github.io/picolisp <https://aw.github.io/picolisp>* On Sun, Jan 24, 2016 at 8:33 AM, Greg Lee <gleetb...@earthlink.net> wrote: > Hello everyone. > > I recently discovered PicoLisp, and like a few other newcomers, I was > initially disappointed to find that there was no support for floating point > arithmetic. After reading the excellent documentation, I came to understand > why that is so and also why fixed point arithmetic provides a fully > acceptable alternative. > > As I found out more and more about PicoLisp and what it can do, I was > constantly amazed at its versatility and usability. When I found out about > the PicoLisp capability to interface with C through the "native" and "gcc" > functions, I decided to write a library to implement floating point > arithmetic for PicoLisp "just because". > > Although this was my first interaction with PicoLisp (or any other Lisp, > for that matter), I found the process remarkably easy. The result of my > project is the picolisp-fp library for 64 bit PicoLisp, available at > https://github.com/gleetbone/picolisp-fp. > > In the IEEE-754 floating point standard as implemented in C and other > languages, floating point values are represented as 32 or 64 bit words. > Certain bit fields in these words are interpreted as the sign, the > exponent, and the mantissa. However, in computer memory, each floating > point value is simply a 32 or 64 bit machine word. The picolisp-fp library > uses PicoLisp integers to hold floating point words, and passes them to > external C functions to be "interpreted" and acted upon as floating point > values. Floating point results are passed back to PicoLisp "re-interpreted" > as integers. No change to PicoLisp is required - the picolisp-fp functions, > through calls to the "gcc" or "native" function, take integers as arguments > and return integers. The library provides basic math for single and double > precision floating point values as well as all of the trigonometric and > transcendental functions from the C <math.h> header file, along with > functions that translate between single precision values, double precision > values, fixed point values, and their string representations. > > The library is provided in two forms - an inline version that uses the > "gcc" function, and a separately compiled version that consists of both an > external shared library (compiled from a C file) and a PicoLisp file that > uses the "native" function to access the dynamic library. The GitHub > repository also contains examples and unit tests. Although I have only run > the library on x86_64 Linux, I see no reason why it shouldn't also work > with other 64 bit CPUs and operating systems. > > Of course, this library is the solution to a nonexistent problem, but I > think it is possible that someone might find it useful in some special > cases. And at least it provides the means to shut up newbies like me who > demand floating point support! > > Thanks, > > Greg Lee > > -- > UNSUBSCRIBE: mailto:firstname.lastname@example.org?subjectUnsubscribe >