# Floating point on uLisp?

#1

Hi

I was wondering if floating point would ever come to ulisp.
It would be a great enhancement.

Regards ,

Ronny

#2

Thank you for the suggestion.

I think it would be relatively straightforward to add floating point to the 32-bit versions of uLisp, for the Arduino Due, Zero, and MKRZero, because the Lisp cells are large enough to hold a 32-bit floating-point value.

What sort of applications do you have in mind that require floating point?

#3

Hi

I have for instance a magnetometer sensor , to act as a compas.
It needs to calculate the arctan
of 2 coordinates being x en y

Kind regards ,

Ronny

#4

Hi

Can this be done in lisp itself , or does it require extra code in the arduino software ?

Regards ,

Ronny

#5

Dear Ronny,

From what it looks like to me … you aren’t trying to do a neural network, are you? ;) Because that just looks like a typical activation function…

Is it “doable in Lisp itself”? Let’s say: “kind of”. In theory: totally. In practice: it will take an eternity to perform. So unless @johnsondavies has time for that, you will not have “real” floating point.

However: allow me to propose an alternative: How about a good look-up-table (perhaps a classic plist or alist) and extrapolation?

And then, you could simply treat “floats” as “large integers”. That is, e.g. 1.234 can be expressed as 1234. Your table might have a value for 1.2 and a value for 1.3 (that is, a value for 1200 and a value for 1300). You call up these two values, determine their difference, multiply their difference with 34, divide their difference by 100, and - there you go. You could even just “threshold it”, and say, just take the value for 1.2 (or 1200, here). You may make your table more fine-grained around 0, then, and more coarse towards the ends. As to the “ends” … a slight advice: give a minimal and a maximum value which are NOT the asymptotes, so this way you do not end up with weird division-by-zero errors later on.

#6

Hi Aeneas

No I’m not doing a neural network , no knowledge of that.
Let’s hope Johnsondavies has some time to implement it.
There are lot of sensors , like my magnetometer how require floating point.
I also find it a great enhancement for uLisp or whatever embedded language
Like Forth for example.

Anyways your approach to interpolation gives me some thinking about the matter.
Maybe a lookuptable for arctan could be a in between solution

Thanks for the idea :-) !

Ronny

#7

I hacked single floats into the language in an afternoon a few weeks ago. It’s tedious, but doable: https://github.com/sjl/ulisp-sam-samd/commit/414a504a524c2160434b7e50daa02d0f17256133

#8

Hi sjl

Thanks alot , but how to implement it ?
Just adding the code , in the end , to the ulisp.ino ?

#9

Hi Sjl

I found the code on github.
Great !!

What I notice however is the accuracy.
Let say (* 2.5 2.5) gives 6.24999 instead of 6.25
Is there a way to round the result ??
But apart from that nice piece of code.

Kind regards
Ronny

#10

The actual numbers aren’t inaccurate (well, not any more than single floats are by their very nature), it’s my printing routine (`pfloat`) that’s causing what you see.

There are ways to print floating point numbers nicely and accurately, like this: https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfkieTlklRzN.pdf but I didn’t have the time to implement that when I was writing that chunk of code.

#11

Hi Sjl

What you wrote isn’t just a chunk of code IMHO.
I don’t have the knowledge to write something like that
I’m an Electronics engineer whit some knowledge of software.
I know assembler , some C code , forth , and a little lisp , because lisp is very close to forth.
You did a great job.
If you could finish this code with more accuracy , then maybe davies could implement it in future versions ??

Kind regards ,

Ronny

PS: meanwhile I’m gonna use your floating routines for more calculations
like sin , cos , …

#12

The latest release of the ARM version of uLisp now includes floating-point support; see:

Floating-point features

#13