Reputation: 1639
I'm attempting to write something in Common Lisp to read and write data in a particular binary format, as a way of both learning Lisp and hopefully ending up with a useful (or at least interesting) tool. I started off with the parser project in Practical Common Lisp and have been building up from there. One thing I need that's not in there is floating-point numbers of arbitrary length (in bytes). CL provides ldb
for unsigned integers, and from there, signed ones weren't too hard to build – is there any comparable useful functionality for getting and setting the sign, exponent, and fraction components of a floating-point number? I don't want to have to use libraries for this, since part of the point is to get practice writing code, but I don't really want to spend time re-implementing what's already built-in, either.
Upvotes: 1
Views: 560
Reputation: 132
If you're reading binary formatted floats, you'll need to implement your own parser for it. More than likely it's going to be an IEEE Floating Point encoded value. You can find all the information you need on Wikipedia: https://en.wikipedia.org/wiki/IEEE_754
As per getting at the various components of a floating point value once it's in CL, you can use the various functions here: http://clhs.lisp.se/Body/f_dec_fl.htm
Upvotes: 1