PDA

View Full Version : F32 - 90 minutes of fun - user caveat

g3cwi
04-06-2012, 08:33 PM
...before realising that Fmul(32.5 * 10) did not work because it was not Fmul(32.5 * 10.0). You cannot begin to imagine how many things I have tried!

Grrrrr. More beer.:smile:

Cheers

Richard

ElectricAye
04-07-2012, 02:55 AM
.....You cannot begin to imagine how many things I have tried!...

Oh yes I can. For I have been there. And done that.

More than I care to admit.

Hey, wait a second. Are you using the FloatMath object or what??

Heater.
04-07-2012, 05:04 AM
Me too. Beer definitely helps.

It's at times like this you wish that Spin had proper types.

I just started learning Javascript for the first time where there are similar problems. OK JS has integers and floats but it will silently convert numbers to strings when using the "+" operator. So:
a = 2;
b = "2";
c = a + b;
d = a * b;

Makes c equal to the string "22"
But d equal to the number 4.

ElectricAye
04-07-2012, 05:18 AM
...
Hey, wait a second. Are you using the FloatMath object or what??

The reason I asked is because the only float math objects I know about don't use an asterisk, they use a comma.

So it wouldn't be Fmul(32.5 * 10.0)

Instead it would be Fmul(32.5, 10.0)

But maybe you guys have some object I don't know about?

g3cwi
04-07-2012, 06:43 AM
Hi ElectricEye

Just a typo on my behalf in the OP.

Cheers

Richard

Martin_H
04-07-2012, 12:27 PM
For my robot arm project I used floating point math for the inverse kinematics. They typeless nature of Spin made it easy to accidentally use an integer operation on a floating point number and vice versa. I should have record my bugs for an out takes video because the robot arm would go wonky in funny ways. Looking at the code I think your addition of the .0 caused the expression to be evaluated by the compiler and not at run time. That's certainly one way to fix things.

A general problem with Spin is that it doesn't support floating point directly, but many compiler constants (e.g. Pi) are expressed as floating point. The Spin pre-processor can also construct floating point constants so you get lured into using floating point when it would probably be better to use a fixed point solution. For example Trig on the Basic Stamp is done entirely using integer math and binary radians, so Spin could be improved if a good fixed point math package exited.

BTW I did find a fixed point library in the OBEX, but it was written in Spin and was slower than F32.

Update: The original poster said it was a typo and they used a comma, so it wasn't fixed by the pre-processor.

localroger
04-07-2012, 02:43 PM
Spin at least has an excuse for its typelessness; it's a very bare bones, efficient environment optimized for limited RAM. Javascript, by contrast, has no excuse at all for that braindead conflation of strings and numbers which serves no useful purpose at all and makes the language slower and less efficient to implement.

Martin_H
04-07-2012, 05:02 PM
Spin at least has an excuse for its typelessness; it's a very bare bones, efficient environment optimized for limited RAM. Javascript, by contrast, has no excuse at all for that braindead conflation of strings and numbers which serves no useful purpose at all and makes the language slower and less efficient to implement.

Grr Argh JavaScript! I hate that language with the heat of a billion exploding Suns!

* Did you know that "var undefined = 1;" will work in JavaScript and then break all code that tests against undefined? This is because undefined is not a keyword like null, but an undefined variable.

* That myVar === undefined is the preferred way to test for undefined. No that's not a typo it's a triple equal which is the strict comparison operator which doesn't type convert by default.

* Pointers can be either undefined or null, so you need to check for both everywhere!

* JavaScript uses 64 bit reals for all numbers which means that you can write for loops that won't terminate due to truncation errors!

* It's object system is sort of cool in a language geek sort of way because it's really an OO construction toolkit. This means you get to build your own OO type system from it. The problem is everyone builds their own so nothing interoperates.

It's easy to write simple stuff (parameter validation, dynamic web forms, etc), but extremely difficult to write reliable large systems in it. There's also a fairly large number of people in the web programming community thinking that every thing should be written in it.

Heater.
04-16-2012, 09:29 AM
Martin_H,

I've been avoiding JS for donkeys years. Just now I started looking into it for stuff at work so...

Did you know that "var undefined = 1;" will work then break all code that tests against undefined?

Thanks for the heads up on that. Even jslint checks out OK when you do that! Luckily my syntax highlighting editor (vim) colors "undefined" as a key word.

JavaScript uses 64 bit reals for all numbers which means that you can write for loops that won't terminate due to truncation errors!

Yes, but this is an issue in any language with floats. Things that you think should be equal may not be. On the plus side integer values go to 2^53 even on 32 bit machines.

It's object system is sort of cool in a language geek sort of way because it's really an OO construction toolkit

Yeah, that is as confusing as hell.

It's easy to write simple stuff (parameter validation, dynamic web forms, etc), but extremely difficult to write reliable large systems in it

I would have thought so, but then there I guys doing things like this http://qooxdoo.org/

(http://qooxdoo.org/)Perhaps the approach is "don't write large systems in it". Rather create a lot of small inter-operating parts.

There's also a fairly large number of people in the web programming community thinking that every thing should be written in it.

Looking at it as a "WEB programming outsider" I have always thought that everything about WEB programming sucked. On the browser you have a mess of HTML, the toy JS language, CSS, the DOM ,,,gack. On the server side you have a mess of Apache, the toy PHP language (and others), templating systems etc etc etc. All this chaos hooked up with a bunch of odd protocols and XML (more gack). Looking at this Tower of Babel I wonder how they get anything to work:)

Would it not be better to have the same language on all nodes in the system no matter if they are servers or browsers or whatever?

Enter JS on the server. Which I found in one case is faster than our old C++ implementation with one fourth the amount of code and a lot easier to modify.

lonesock
04-16-2012, 04:55 PM
@Richard: Heh, yep, done that myself, and you'd think I know better! In fact I just did it trying to define a Pi * 2 constant. [8^)

Jonathan